您的测试套件必须至少包含一个测试

时间:2018-06-13 18:00:24

标签: reactjs jestjs enzyme

我已经在我的项目中更新了今天的一些依赖项,但它运行得非常顺利。现在,当我要推动它时,我开始了我的测试。繁荣。所有人都扔了:

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",

这就是我的示例测试文件的样子:

/共享/组件/应用/ MyRoute / __测试__ / 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配置

  "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"
},

5 个答案:

答案 0 :(得分:1)

所以,我找到了答案。

here中的Note表示,如果我们将babel-jest与我们自己的预处理器一起使用,则必须在babel-jest中明确定义transform选项。

"^.+\\.jsx?$": "babel-jest"添加为transform配置中的第一个选项非常重要。

答案 1 :(得分:1)

确保描述/期望未导入变量

就我而言,IDE(VSCode)自动从另一个库中导入变量describe

答案 2 :(得分:0)

确保您至少有一个describe / it / expect

就我而言,我只写了describe / expect测试并收到了此错误消息

答案 3 :(得分:0)

也许你忘了它()块:

也许你有一个错误,在某处代码是这样的:

describe('my test', () => {
    expect(...)...;
});

替换为:

describe('my test', () => {
    it('some text', () => {
        expect(...)...;
    })
});

答案 4 :(得分:0)

另一种选择是使用 --passWithNoTests 参数调用 Jest,如文档 here 所述。

相关问题