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