今天,我已经在我的项目中更新了一些依赖项,但是它进行得非常顺利。现在,当我要推动它的时候,我开始了我的测试。砰的一声。他们都扔:
Your test suite must contain at least one test.
我的包裹:
"jest": "23.1.0",
"jest-enzyme": "^6.0.1",
"jest-webpack-alias": "^3.3.3",
"jsdom": "^11.2.0",
"jsdom-global": "^3.0.2",
"enzyme": "3.3.0",
"enzyme-adapter-react-16": "^1.1.0",
"enzyme-to-json": "3.3.4",这就是我的示例测试文件的样子:
/shared/components/App/MyRoute/__tests__/MyRoute.test.js
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react';
import { shallow } from 'enzyme';
import { ContactsRoute } from '../Route';
describe('<ContactsRoute />', () => {
test('renders', () => {
const wrapper = shallow(<ContactsRoute t={key => key} />);
expect(wrapper).toMatchSnapshot();
});
});我不知道他们为什么突然停止跑?
编辑-添加我的jest config
"jest": {
"collectCoverageFrom": [
"shared/**/*.{js,jsx}"
],
"globals": {
"JWT_SECRET": "local",
"IS_TEST": "true"
},
"snapshotSerializers": [
"<rootDir>/node_modules/enzyme-to-json/serializer"
],
"testPathIgnorePatterns": [
"<rootDir>/(build|internal|node_modules|flow-typed|public|shared/services)/"
],
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/_test_config_/mocks/fileMock.js"
},
"testURL": "http://localhost:3005",
"transform": {
".": "<rootDir>/_test_config_/preprocessors/webpackAlias.js",
"^.+\\.css$": "<rootDir>/_test_config_/preprocessors/cssTransform.js",
"^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/_test_config_/preprocessors/fileTransform.js"
},
"setupFiles": [
"<rootDir>/_test_config_/preprocessors/polyfills.js"
],
"setupTestFrameworkScriptFile": "./node_modules/jest-enzyme/lib/index.js"
},发布于 2020-08-28 03:43:36
确保未导入描述/ it/ expect变量
在我的示例中,IDE( VSCode )自动从另一个库导入变量describe。
发布于 2021-08-29 01:11:35
如果所有其他响应都失败了,如果您有任何名为test.js的文件,Jest将期望该文件包含一个测试。
我使用一个名为test.js的文件手动测试一些东西,Jest抛出了这个错误。我将该文件重新命名为其他文件(例如: 123.js),并停止收到此错误消息。
发布于 2021-05-15 05:53:58
可能是你忘了它()块:
也许你犯了一个错误,在某个地方,代码是这样的:
describe('my test', () => {
expect(...)...;
});代之以:
describe('my test', () => {
it('some text', () => {
expect(...)...;
})
});https://stackoverflow.com/questions/50843511
复制相似问题