[Solved] Test suite failed to run Your test suite must contain at least one test. at node_modules/@jest/core/build/TestScheduler.js:242:24 at asyncGeneratorStep (node_modules/@jest/core/build/TestScheduler.js:131:24)

Test suite failed to run Your test suite must contain at least one test

I started testing my reducer functions and the components of my react project by using built-in Jest library, when I was started to create some test files to the reducers pure functions, I was facing the issue i.e I mentioned in the below section.

I have created todo.test.js


import toDos from '../Store/ConfigureStore';
const stateBefore = [];
const action = {
    type: 'ADD_TODO',
    id: 0,
    text: 'Learn Redux'
}
const stateAfter = [
    {
        id: 0,
        text: 'Learn Redux',
        completed: false
    }
];
 expect(toDos(stateBefore, action)).toEqual(stateAfter); 

If I run the code with the above changes, I faced the below error.

Test suite failed to run Your test suite must contain at least one test.

Solution:

I had a mistake, and in code like this, I followed the below approaches to resolve the issue. I wrote just a describe / expect test and got this error message. So, we can apply the following approaches to resolve the issue.

Approch 1: Make sure describe / it/ expect

Yes, I was missing that describe / it/ expect methods in my todo.test.js file. After I changed the expect a statement like the below code changes, I mean after I wrap the expect code block within the describe and it function, my test cases are passed.


import toDos from '../Store/ConfigureStore';
const stateBefore = [];
const action = {
    type: 'ADD_TODO',
    id: 0,
    text: 'Learn Redux'
}
const stateAfter = [
    {
        id: 0,
        text: 'Learn Redux',
        completed: false
    }
];

describe('my test', () => {
    it('some text',
        () => {
               expect(toDos(stateBefore, action)).toEqual(stateAfter);
        });
});

After I make changes to my code and run the below command in the terminal, my test cases are passed.

npm test

Approach 2: Replace “test” with “it”

I have removed import statements like, at the top of the test file, after going through some articles and finding that the IDE( VSCode ) automatically imports the variable from another library. So, my final version of the todo.test.js file looks like this

Note: In the above snippet I just mentioned it block syntax structure and remove the state and action objects.

After I make changes to my code and run the below command in the terminal, my test cases are passed.

npm test

Conclusion:

As a beginner, we all do mistakes while writing the test cases to our components, functions, reducer.

So, Jest is a good test library that comes with different advantages to testing the application in very simple ways. we carefully learn the concepts of the Jest library and use them for better tests of the application, I hope you find them helpful.

Default image
Shivaraju M

Over 3+ years experience in IT industry, good knowledge in . Net-based Web applications, windows applications, web services, and SPAs. I have played
multiple roles related to technical delivery in multiple domains while working on over 10+ technologies. I am
currently focused on continuous improvement and agile project management.

Leave a Reply