Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs TypeError:test.each不是React test中的函数_Reactjs_Jestjs_Create React App - Fatal编程技术网

Reactjs TypeError:test.each不是React test中的函数

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); }, ); 当我运

我正在阅读我的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);
  },
);
当我运行测试时,出现以下错误:

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);
});