Skip to content

Instantly share code, notes, and snippets.

@prasann
Created September 17, 2017 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasann/84432c625f08c4156ad0e3a5ca188ec6 to your computer and use it in GitHub Desktop.
Save prasann/84432c625f08c4156ad0e3a5ca188ec6 to your computer and use it in GitHub Desktop.
Sample Jest test to mock localeString
import * as helpers from '../src/helpers';
describe('formatDate', () => {
it('should invoke localString implementation to format date ', () => {
const localStringMock = jest.fn();
const mockDate = { toLocaleString: localStringMock };
helpers.formatDate(mockDate);
expect(localStringMock).toHaveBeenCalledWith('de-DE', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment