I get the error:
TypeError: (0 , _jest.test) is not a function
when trying to use npm test
.
I think it could be related to configurations. How can I fix this problem?
File sum.js
function sum (a, b) {
return a + b
}
export default sum
File tests/sum.test.js
import sum from '../src/sum.js'
import { test, expect } from 'jest'
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})
File package.json
"devDependencies": {
"babel-eslint": "7.1.1",
"eslint": "3.18.0",
"eslint-plugin-react": "6.10.0",
"standard": "9.0.2",
"webpack": "2.2.1",
"jest": "21.0.1",
"jest-cli": "21.0.1",
"babel-jest": "21.0.0",
"regenerator-runtime": "0.11.0"
},
and
"scripts": {
"test": "standard && jest",
"format": "standard --fix",
"start": "webpack-dev-server --config webpack.config.dev.js",
"build": "webpack --config webpack.config.prod.js"
},
I get the error:
TypeError: (0 , _jest.test) is not a function
when trying to use npm test
.
I think it could be related to configurations. How can I fix this problem?
File sum.js
function sum (a, b) {
return a + b
}
export default sum
File tests/sum.test.js
import sum from '../src/sum.js'
import { test, expect } from 'jest'
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})
File package.json
"devDependencies": {
"babel-eslint": "7.1.1",
"eslint": "3.18.0",
"eslint-plugin-react": "6.10.0",
"standard": "9.0.2",
"webpack": "2.2.1",
"jest": "21.0.1",
"jest-cli": "21.0.1",
"babel-jest": "21.0.0",
"regenerator-runtime": "0.11.0"
},
and
"scripts": {
"test": "standard && jest",
"format": "standard --fix",
"start": "webpack-dev-server --config webpack.config.dev.js",
"build": "webpack --config webpack.config.prod.js"
},
Share
Improve this question
edited Oct 13, 2020 at 19:53
Peter Mortensen
31.6k22 gold badges110 silver badges133 bronze badges
asked Sep 7, 2017 at 7:15
RadexRadex
8,58724 gold badges60 silver badges96 bronze badges
2 Answers
Reset to default 9Remove this line:
import { test, expect } from 'jest'
You don't need to import anything from Jest. See example.
I've got it running with flow using
import expect from "expect";
const test = window.test;
Maybe it helps you, too. It seems to make flow treat them both as any
, which is far from perfect, but at least the other parts of the file can be checked.
A slightly better "solution" is to make an own file my-test.test.js
containing
export const test = window.test;
export const expect = window.expect;
test("dummy", () => {});
and use it like
import {test, expect} from '../my/my-test.test';
This concentrates the ugliness in a single file.