[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

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.

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.

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.

Post a Comment

Previous Post Next Post