Skip to content

Commit

Permalink
support jest.setSystemTime
Browse files Browse the repository at this point in the history
  • Loading branch information
puglyfe committed May 6, 2024
1 parent d117b22 commit 443e9d7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/transformers/jasmine-globals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,24 @@ test('jasmine.clock()', () => {
jasmine.clock().install();
jasmine.clock().uninstall();
jasmine.clock().tick(50);
jasmine.clock().mockDate(new Date(2013, 9, 23));
`,
`
jest.useFakeTimers();
jest.useRealTimers();
jest.advanceTimersByTime(50);
jest.setSystemTime(new Date(2013, 9, 23));
`
)
})

test('not supported jasmine.clock()', () => {
wrappedPlugin(`
jasmine.clock().mockDate(new Date(2013, 9, 23));
jasmine.clock().unknownUtil();
`)

expect(consoleWarnings).toEqual([
'jest-codemods warning: (test.js line 2) Unsupported Jasmine functionality "jasmine.clock().mockDate(*)".',
'jest-codemods warning: (test.js line 3) Unsupported Jasmine functionality "jasmine.clock().unknownUtil".',
'jest-codemods warning: (test.js line 2) Unsupported Jasmine functionality "jasmine.clock().unknownUtil".',
])
})

Expand Down
7 changes: 4 additions & 3 deletions src/transformers/jasmine-globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,10 @@ export default function jasmineGlobals(fileInfo, api, options) {
break
}
case 'mockDate': {
logWarning(
'Unsupported Jasmine functionality "jasmine.clock().mockDate(*)".',
path
// make it `jest.setSystemTime(date)`
path.node.callee = j.memberExpression(
j.identifier('jest'),
j.identifier('setSystemTime')
)
break
}
Expand Down

0 comments on commit 443e9d7

Please sign in to comment.