dev_el
dev_el

Reputation: 2947

Why can't my test files be found when running mocha?

I am following step 1 of this tutorial

I have the following folder structure:

├── lib
│ ├── json
│ │ ├── messages.json
│ │ └── testMessages.json
│ └── model.js
├── test
│ └── model.test.js
└── package.json

My package.json has the following to run the mocha tests

“test”: “mocha -r esm ./test/* —exit”,

But I get the following error

> [email protected] test /Users/lee33ya/Desktop/mern-app/backend
> mocha -r esm ./test/* --exit

Error: No test files found: "./test/*"
npm ERR! Test failed.  See above for more details.

What am I doing wrong and what can I do to resolve my tests not running?

My github

Upvotes: 7

Views: 8527

Answers (2)

programmingTantrik
programmingTantrik

Reputation: 180

while doing a mocha test these things you should follow

  1. first npm init this initializes the package.json file

  2. Then add the following inside the package.json file

  3. "script": {"test" : "mocha"} (this should be inside the main { })

  4. then install mocha as a dependency by doing npm install mocha -D

  5. then make a test folder in the main file and put the .js file you want to test

  6. then run npm test

if i didn't explain correctly i am sorry and this is my first answer so :)

here is a very good article on mocha if you want to see

https://blog.logrocket.com/a-quick-and-complete-guide-to-mocha-testing-d0e0ea09f09d/

Upvotes: 0

user3416686
user3416686

Reputation: 86

Found two issues

  1. Your package.json file is misplaced. Place it with ".gitignore" file. And run "npm install"
  2. "chai" is required. Do "npm install chai"

Output

Upvotes: 5

Related Questions