Reactjs TypeError:test.each不是React test中的函数
我正在阅读我的create react应用程序的文档:Reactjs TypeError:test.each不是React test中的函数,reactjs,jestjs,create-react-app,Reactjs,Jestjs,Create React App,我正在阅读我的create react应用程序的文档: 在您的测试文件中,Jest将这些方法和对象中的每一个放入全局环境中。您无需要求或导入任何东西即可使用它们。 我已尝试复制Jest测试。每个示例代码都复制到我的测试中: test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])( '.add(%i, %i)', (a, b, expected) => { expect(a + b).toBe(expected); }, ); 当我运
在您的测试文件中,Jest将这些方法和对象中的每一个放入全局环境中。您无需要求或导入任何东西即可使用它们。
我已尝试复制Jest测试。每个示例代码都复制到我的测试中:
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>
我认为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);
});
缺少什么?两年后:此处相同类型错误:每个都不是函数<代码>节点v12.19.0
,npm 6.14.8
,对每个^26.6.2
开玩笑。你能解决你的问题吗?
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);
});