Last active
June 8, 2020 08:22
-
-
Save himanshuteotia/470272271a53f64424b4b3f9e292ce02 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
test('creates Contract on correct date', () => { | |
const NOW = '2019-05-03T08:00:00.000Z'; | |
const mockDateNow = jest | |
.spyOn(global.Date, 'now') | |
.mockImplementation(() => new Date(NOW).getTime()); | |
const mutation = ` | |
mutation createContract { | |
createContract { | |
startedOn | |
} | |
} | |
`; | |
const response = await graphQLRequestAsUser(mutation); | |
const { data } = response.body; | |
expect(data.startedOn).toEqual(NOW); | |
mockDateNow.mockRestore(); | |
}); | |
// or we can use inside beforeEach and afterEach | |
const now = '2019-05-03T08:00:00.000Z'; | |
let mockDateNow; | |
beforeEach(() => { | |
mockDateNow = jest.spyOn(global.Date, 'now').mockImplementation(() => new Date(now).getTime()); | |
}); | |
afterEach(() => { | |
mockDateNow.mockRestore(); | |
}); | |
test('some test name', () => { | |
//...do some test stuff here | |
}) | |
test('another test name', () => { | |
//...do some more test stuff here | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment