Kendrakstef
Kendrakstef

Reputation: 105

React - Jest : No tests found, exiting with code 0

I'm learning ReactJS for a few weeks but I'm facing an issue that's impossible to solve by myself.

I use create-react-app command to start react project but it is totally impossible to use npm test after that. Even if I don't touch anything in the project, when I try to run npm test I only get "No tests found, exiting with code 0".... When I just create the project there is src/App.test.js but the command found nothing..... :(

Someone I sent the folder succeeded to run the tests.... is it possible that the problem comes from my computer/environment (Windows 10) ?

Thanks for help.

Have a good day

Upvotes: 4

Views: 14812

Answers (4)

m4chei
m4chei

Reputation: 61

As answered by @Kenkradstef, there can be issues with the path your project is in. Had the same problem, with "[" "]" in my path. Full path was something like "C:\Users\xxx\[P]rojects\xxx\".

I moved the project to a different location and it worked.

Can't add a comment because I have no reputation, that's why I am posting this as an answer.

Upvotes: 1

Hyeonmin
Hyeonmin

Reputation: 153

If you are CRA(Create React App) user who is seeking proper answer, try this out in package.json.

`

{
  "name": "Your App",
  "jest": {
    "testMatch": [
      "<rootDir>/src/**/*.test.{js,jsx,ts,tsx}",
      "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}"
    ]
  },
 "version": "0.1.0",
"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --watchAll=false",
    "eject": "react-scripts eject"
  }
}

`

CRA manages jest in package.json. So if you use jest.configure.js in parent route you will get error about route something.
If you want another custom configuration give a changetestMatch.

Upvotes: 4

JASBIR SINGH
JASBIR SINGH

Reputation: 530

Add this line to your "package.json"

  1. open package.json

  2. find scripts in that "test" : "react scripts test" replace this with

    "test": "react-scripts test --watchAll --testMatch **/src/**/*.test.js"
    
  3. Now run npm test.

It works!

Upvotes: 14

Kendrakstef
Kendrakstef

Reputation: 105

Got it!

I found this posts https://github.com/facebook/create-react-app/issues/7660 wich explain that npm test don't work with hidden directories (.xxx).

My projet is under C:\Users\kendr\.babun\cygwin\home\Kendrak\react\myprojet The problem is the .babun !

I move my project in another dir and the test command now works fine!

Upvotes: 4

Related Questions