admin管理员组文章数量:1278976
I am implementing jest to test my React app and have set up a simple test on a utility function I have, but I am getting the error:
Error: Your test suite must contain at least one test.
Have checked my implementation, and I think all is correct - could someone take a look got me?
The file structure for the test and the function is as follows
- __tests__
-- sumObjectValues-test.js
- utils
-- sumObjectValues.js
sumObjectValues.js
is as follows:
const sumObjectValues = (obj, identifier) => {
return obj
.map((el) => { return el[identifier]; })
.reduce((prev, next) => { return prev += next; }, 0);
}
export default sumObjectValues;
And 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);
});
});
Then I have "test": "jest"
in my package.json scripts, but get the following error:
FAIL __tests__/sumObjectValues-test.js (0s) ● Runtime Error - Error: Your test suite must contain at least one test. at onTestResult (node_modules/jest-cli/build/TestRunner.js:143:18) 1 test suite failed, 0 tests passed (0 total in 1 test suite, run time 13.17s) npm ERR! Test failed. See above for more details.
Thanks all :)
N.B.: Was a typo in the it
, but after fixing I am getting a new error:
FAIL __tests__/sumObjectValues-test.js (321.763s) ● sumObjectValues › it takes an array of objects, each with amount values, & sums the values - TypeError: sumObjectValues is not a function at Object. (__tests__/sumObjectValues-test.js:27:10) 1 test failed, 0 tests passed (1 total in 1 test suite, run time 344.008s) npm ERR! Test failed. See above for more details.
I am implementing jest to test my React app and have set up a simple test on a utility function I have, but I am getting the error:
Error: Your test suite must contain at least one test.
Have checked my implementation, and I think all is correct - could someone take a look got me?
The file structure for the test and the function is as follows
- __tests__
-- sumObjectValues-test.js
- utils
-- sumObjectValues.js
sumObjectValues.js
is as follows:
const sumObjectValues = (obj, identifier) => {
return obj
.map((el) => { return el[identifier]; })
.reduce((prev, next) => { return prev += next; }, 0);
}
export default sumObjectValues;
And 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);
});
});
Then I have "test": "jest"
in my package.json scripts, but get the following error:
FAIL __tests__/sumObjectValues-test.js (0s) ● Runtime Error - Error: Your test suite must contain at least one test. at onTestResult (node_modules/jest-cli/build/TestRunner.js:143:18) 1 test suite failed, 0 tests passed (0 total in 1 test suite, run time 13.17s) npm ERR! Test failed. See above for more details.
Thanks all :)
N.B.: Was a typo in the it
, but after fixing I am getting a new error:
FAIL __tests__/sumObjectValues-test.js (321.763s) ● sumObjectValues › it takes an array of objects, each with amount values, & sums the values - TypeError: sumObjectValues is not a function at Object. (__tests__/sumObjectValues-test.js:27:10) 1 test failed, 0 tests passed (1 total in 1 test suite, run time 344.008s) npm ERR! Test failed. See above for more details.Share Improve this question edited Apr 13, 2020 at 14:23 Paul T. Rawkeen 4,1143 gold badges36 silver badges52 bronze badges asked Aug 24, 2016 at 19:24 zeKokozeKoko 4371 gold badge7 silver badges19 bronze badges 6
-
I'm pretty sure Node.js doesn't support ES2015 modules (yet). Try changing
export default sumObjectValues
tomodule.exports = sumObjectValues
. – Mike Cluck Commented Aug 24, 2016 at 20:30 - 1 Ahh, of course, I can add the babel jest module to try to sort that, will give it a go! Thank you :) – zeKoko Commented Aug 24, 2016 at 20:31
- Ah man, this is painful.. I think I need to go sleep. It has run now I have installed babel-jest, but I am getting a new error: FAIL __tests__/sumObjectValues-test.js (321.763s) ● sumObjectValues › it takes an array of objects, each with amount values, & sums the values - TypeError: sumObjectValues is not a function at Object.<anonymous> (__tests__/sumObjectValues-test.js:27:10) 1 test failed, 0 tests passed (1 total in 1 test suite, run time 344.008s) npm ERR! Test failed. See above for more details. – zeKoko Commented Aug 24, 2016 at 21:14
-
I'm just spitballing since I haven't used ES2015 modules in Node yet but have you tried using the
import
syntax instead ofrequire
? – Mike Cluck Commented Aug 24, 2016 at 21:51 - 1 Yes! You beauty! Thanks Mike, that was it, appreciate the help :) – zeKoko Commented Aug 24, 2016 at 22:07
2 Answers
Reset to default 4if('takes an array of objects, each with amount values, & sums the values', () => {
should be
it('takes an array of objects, each with amount values, & sums the values', () => {
If you think to write tests later, You can just ignore them with this
test.skip('skip', () => {});
本文标签: javascriptJest Error Your test suite must contain at least one testStack Overflow
版权声明:本文标题:javascript - Jest: Error: Your test suite must contain at least one test - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741283358a2370133.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论