Created
September 17, 2017 14:56
-
-
Save prasann/84432c625f08c4156ad0e3a5ca188ec6 to your computer and use it in GitHub Desktop.
Sample Jest test to mock localeString
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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