我正在阅读我的create-react-app react应用程序的文档:
https://jestjs.io/docs/en/api.html
In your test files, Jest puts each of these methods and objects into the global environment. You don't have to require or import anything to use them.
我尝试将Jest test.each
示例代码复制到测试中:
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
);
运行测试时出现此错误:
Test suite failed to run
TypeError: test.each is not a function
at Object.<anonymous> (sorting.test.js:71:6)
at <anonymous>
我的Jest版本正确:
"devDependencies": {
"jest": "^23.6.0"
}
我认为test
应该是全局的,就像it
一样-这里的第二个测试通过了,这就是整个测试:
import {isValidNumber} from '../sorting';
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'.add(%i, %i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
);
it('Should reject no args', () => {
expect(isValidNumber(undefined)).toEqual(false);
});
缺少什么?