TypeError on Jest example test suite

Viewed 942

I am trying to run the jest test suite provided by the official document and it gives the following error in terminal.

FAIL  test/sum.test.js
  ● Test suite failed to run

    TypeError: (0 , _vm(...).compileFunction) is not a function

      at Runtime._execModule (node_modules/jest-runtime/build/index.js:1166:56)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.041 s
Ran all test suites.
(node:15186) ExperimentalWarning: The fs.promises API is experimental
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! PhotoGallery@1.0.0 test: `jest`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the PhotoGallery@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Here are my test files(sum.test.js)

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

sum.js

function sum(a, b) {
  return a + b;
}
module.exports = sum;

both are in the same folder root/test

1 Answers

Normally when a package itself is failing to run it's because of a mismatch between the package and the versions of its dependencies or of node. Jest is trying to use something that either doesn't exist in your files or is not working the way jest expects it to work, which is giving you the error. I ran a couple tests with nvm and got this jest error with node v10.*; You will probably want to either upgrade to a more recent version of node or downgrade jest.

Related