firsttris / vscode-jest-runner

Simple way to run or debug one or more tests from context menu, codelens or command plalette
https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner
MIT License
265 stars 124 forks source link

"Modern" fake-timer implementation doesn't work with typescript #210

Closed JoichiroK closed 2 years ago

JoichiroK commented 3 years ago

index.js

export function testFunction() {
    console.log('hello world');
}

index.test.js

import { testFunction } from ".";

test('test fake timer', () => {
    jest.useFakeTimers('modern');
    jest.setSystemTime(new Date());

    testFunction();

    let allSuccess = true;
    expect(allSuccess).toBeTruthy();
});

result:

 FAIL  ./index.test.ts
  × test fake timer (3 ms)

  ● test fake timer

    TypeError: setSystemTime is not available when not using modern timers

      3 | test('test fake timer', () => {
      4 |     jest.useFakeTimers('modern');
    > 5 |     jest.setSystemTime(new Date());
        |          ^
      6 |
      7 |     testFunction();
      8 |

      at Object.setSystemTime (node_modules/jest-runtime/build/index.js:2035:17)
      at Object.<anonymous> (index.test.ts:5:10)

Hello. I run the test include pass "modern" argument to useFakeTimers function, but useFakeTimers looks not working. And, This test pass that use normal jest module

PS C:\Users\xxx\Documents\test> npm test

> test@1.0.0 test C:\Users\xxx\Documents\test
> jest

ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
 PASS  ./index.test.ts
  √ test fake timer (12 ms)

  console.log
    hello world

      at testFunction (index.ts:2:13)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.437 s, estimated 2 s
Ran all test suites.

What happend? What do you think about this issue?

More environment information, Please reference this repo below. https://github.com/JoichiroK/testForJestRunner

Visual Studio Information: Version: 1.59.1 (user setup) Commit: 3866c3553be8b268c8a7f8c0482c0c0177aa8bfa Date: 2021-08-19T11:56:46.957Z Electron: 13.1.7 Chrome: 91.0.4472.124 Node.js: 14.16.0 V8: 9.1.269.36-electron.0 OS: Windows_NT x64 10.0.19042

JoichiroK commented 2 years ago

Hi everyone. After updating Jest, the test now works correctly. Therefore, it is assumed that the version of Jest was old or there was some kind of bug.

Sorry for the delay in reporting.