'Your test suite must contain at least one test
I have updated some of the dependencies today in my project, but it went through really smoothly. Now, when I'm about to push it, I started my tests. And boom. All of them throw:
Your test suite must contain at least one test.
My packages:
"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",
And that is how my sample test file looks like:
/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();
});
});
I have no idea why they stopped running so suddenly?
Edit - adding my 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"
},
Solution 1:[1]
make sure describe / it/ expect variables are not been imported
In my case, the IDE( VSCode ) automatically import the variable describe from another library.
Solution 2:[2]
Make sure that you have at least one describe / it / expect
In my case, i wrote just a describe / expect test and got this error message
Solution 3:[3]
If all the other responses fail, if you have any files named test.js, Jest will expect that file to contain a test.
I was using a file named test.js to manually test some stuff, and Jest was throwing this error. I re-named the file to something else (eg: 123.js) and I stopped getting this error message.
Solution 4:[4]
May be you forgot it() block:
maybe you have a mistake and in somewhere code is like this:
describe('my test', () => {
expect(...)...;
});
replace it with:
describe('my test', () => {
it('some text', () => {
expect(...)...;
})
});
Solution 5:[5]
Make sure that your describe function is not async
// Wrong
describe('setPackages', async () => {
// ...
});
// Correct
describe('setPackages', () => {
// ...
});
Solution 6:[6]
So, I found the answer.
The Note in here says that if we are using babel-jest alongside with our own preprocessors, the babel-jest has to be explicitly defined in the transform option.
It is important to add "^.+\\.jsx?$": "babel-jest" as the first option in the transform config.
Solution 7:[7]
Another option is to call Jest with the --passWithNoTests argument, as documented here.
The flag is useful when you don't know how many tests a script will run, such as with git commit hooks.
Solution 8:[8]
another issue which raises this Error is when you have put some none-test files into your __test__ directory.
All files in your __test__ directory must include some tests to run.
Solution 9:[9]
Might happen when you have a test file but the contents are not saved? Try saving the file before running the tests.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oboo Cheng |
| Solution 2 | Fragalli |
| Solution 3 | nkhil |
| Solution 4 | Jafar Amini |
| Solution 5 | mufasa |
| Solution 6 | mdmb |
| Solution 7 | |
| Solution 8 | Sina |
| Solution 9 | Last of us |
