Skip to content

Instantly share code, notes, and snippets.

@himanshuteotia
Last active June 8, 2020 08:22
Show Gist options
  • Save himanshuteotia/470272271a53f64424b4b3f9e292ce02 to your computer and use it in GitHub Desktop.
Save himanshuteotia/470272271a53f64424b4b3f9e292ce02 to your computer and use it in GitHub Desktop.
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