From 443e9d7dcc4767df3a9587ae1e128aa5ba49d0f5 Mon Sep 17 00:00:00 2001 From: Charley Date: Mon, 6 May 2024 12:36:02 -0500 Subject: [PATCH] support `jest.setSystemTime` --- src/transformers/jasmine-globals.test.ts | 6 +++--- src/transformers/jasmine-globals.ts | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/transformers/jasmine-globals.test.ts b/src/transformers/jasmine-globals.test.ts index 7783acb6..1d74c48d 100644 --- a/src/transformers/jasmine-globals.test.ts +++ b/src/transformers/jasmine-globals.test.ts @@ -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".', ]) }) diff --git a/src/transformers/jasmine-globals.ts b/src/transformers/jasmine-globals.ts index 262341f9..06f97259 100644 --- a/src/transformers/jasmine-globals.ts +++ b/src/transformers/jasmine-globals.ts @@ -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 }