Closed alexgurr closed 3 years ago
Hi, this snippet is not runnable at all. Would you make it possible for me to run by creating a snippet that is runnable to get the error you present? I would assume that trimming it down the the following is sufficient?
import FakeTimers from '@sinonjs/fake-timers';
test('breaks in Jest', async () => {
const clock = FakeTimers.install();
clock.runAll();
clock.uninstall();
});
Then just do jest my-breaking.test.js
? Make it simple to look at and someone might will :smile:
Yep, this should be fine. Updated my issue.
No, that's was not enough.
Doing npx jest
gave me this:
/tmp/jest-test/my.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import FakeTimers from '@sinonjs/fake-timers';
^^^^^^
SyntaxError: Cannot use import statement outside a module
Just switch the import to a require (I'm in a Babel environment and you're directly running with node).
const FakeTimers = require('@sinonjs/fake-timers');
If this works it'll be something to do with the create-react-app
jest environment, in which case you can do:
npx create-react-app temp
cd temp/src
touch tmp.test.js
# add jest test code in the file above
cd ..
npm run test
Not reproducible.
Standalone case
$ cat example.test.js
const FakeTimers = require('@sinonjs/fake-timers');
test('breaks in Jest', async () => {
const clock = FakeTimers.install();
clock.runAll();
clock.uninstall();
});
$ npx jest
PASS ./example.test.js
✓ breaks in Jest (1 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.155 s
Ran all test suites.
$ cd ../
$ npx create-react-app temp
...
$ cp ../test/example.test.js src/
$ npm test
... (Pressing a) to run all tests
PASS src/example.test.js
✓ breaks in Jest (1 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.835 s
Ran all test suites related to changed files.
That was with Node v16. The first case was with the latest v7 of fake-timers and the latest was first done using whatever shipped with Jest (v6.2), and I then redid it using the latest v7 by installing it afterwards and rerunning.
Can reopen if you can provide a reproducible test case.
What did you expect to happen? Code doesn't throw an error.
What actually happens Code throws an error
How to reproduce