我正在实现测试我的React应用程序的jest,并且已经对我拥有的实用程序函数设置了一个简单的测试,但是我收到错误:

错误:您的测试套件必须至少包含一个测试 .

已经检查了我的实现,我认为一切都是正确的 - 有人可以看一下我吗?

测试和功能的文件结构如下

- __tests__
  -- sumObjectValues-test.js
- utils
  -- sumObjectValues.js

sumObjectValues.js如下:

const sumObjectValues = (obj, identifier) => {
    return obj
        .map((el) => { return el[identifier]; })
        .reduce((prev, next) => { return prev += next; }, 0);
}

export default sumObjectValues;

和sumObjectValues-test.js:

const obj = [
    {
        "id": 0,
        "item": "Tesla Model S",
        "amount": 85000
    },
    {
        "id": 1,
        "item": "iPhone 6S",
        "amount": 600
    },
    {
        "id": 2,
        "item": "MacBook Pro",
        "amount": 1700
    }
];

const identifier = "amount";


jest.unmock('../client/utils/sumObjectValues'); // unmock to use the actual implementation of sumObjectValues

describe('sumObjectValues', () => {
    if('takes an array of objects, each with amount values, & sums the values', () => {
        const sumObjectValues = require('../client/utils/sumObjectValues');
        expect(sumObjectValues(obj, identifier)).toBe(87300);
    });
});

然后我在我的package.json脚本中有 "test": "jest" ,但是得到以下错误:

FAIL tests / sumObjectValues-test.js(0s)●运行时错误 - 错误:您的测试套件必须至少包含一个测试 . 在onTestResult(node_modules / jest-cli / build / TestRunner.js:143:18)1测试套件失败,0测试通过(1个测试套件共0个,运行时间13.17秒)npm ERR!测试失败 . 请参阅上文了解更多详情 .

谢谢大家:)

*** Was a typo in the it, but after fixing I am getting a new error: ***

FAIL tests / sumObjectValues-test.js(321.763s)●sumObjectValues>它接受一个对象数组,每个对象都有数值,并对这些值求和 - TypeError:sumObjectValues不是Object的函数 . (tests / sumObjectValues-test.js:27:10)1测试失败,0测试通过(1个测试套件共1个,运行时间344.008s)npm ERR!测试失败 . 请参阅上文了解更多详情 .