I am trying to add Jest tests to a vanilla JS project. I installed Jest with npm, and created an example test file:
// file example.test.js
const { expect } = require("@jest/globals");
const { test } = require("jest-circus");
const one = 1;
test("example test", () => {
expect(one).toBe(1);
});
But I am getting the following error:
FAIL ./example.test.js
● Test suite failed to run
Your test suite must contain at least one test.
at onResult (node_modules/@jest/core/build/TestScheduler.js:175:18)
at Array.map (<anonymous>)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.437 s
Ran all test suites.
Not sure what might be wrong? I clearly have a test/expect block in the test file. I also tried changing test
to it
but that had no effect.
CodePudding user response:
You should import test
function from @jest/globals
package.
const { expect, test } = require('@jest/globals');