ReferenceError: test is not defined with Jest

10,667

Seems related to this issue: https://github.com/facebook/jest/issues/9538

Try upgrading your node version to at least v10.14.2 or downgrading jest to at most v25.2.2.

Share:
10,667
Wolf Fivousix
Author by

Wolf Fivousix

Updated on June 14, 2022

Comments

  • Wolf Fivousix
    Wolf Fivousix almost 2 years

    I am trying to run the most basic example with Jest, yet I don't seem to be able to. Followed the instructions here: https://jestjs.io/docs/en/getting-started.html

    • npm init -y (for a base project)
    • npm install --save-dev jest
    • create sum.js file.
    • create sum.test.js file.
    • update "test" script.
    • npm run test.

    Boom, reference error. What am I missing here?

    • npm v6.13.7
    • node v10.13.0
    • jest v26.0.1

    This is my console output:

    FAIL  ./sum.test.js
      ● Test suite failed to run
        ReferenceError: test is not defined
          1 | const sum = require('./sum');
          2 |
        > 3 | test('adds 1 + 2 to equal 3', () => {
            | ^
          4 |   expect(sum(1, 2)).toBe(3);
          5 | });
          at Object.<anonymous> (sum.test.js:3:1)
        Test Suites: 1 failed, 1 total
    Tests:       0 total
    Snapshots:   0 total
    Time:        0.957 s
    Ran all test suites.
    (node:21384) ExperimentalWarning: The fs.promises API is experimental
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! [email protected] test: `jest`
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] test script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  • Wolf Fivousix
    Wolf Fivousix almost 4 years
    Friend, thank you so much! I don't know why I had such an older version of Node, but after updating it to v12.17, everything works! =)