44

I'm using [email protected] on Mac High Sierra. I want to run tests that were setup in this Stratum client project. I have run npm install successfully. But when I try and run individual tests, I get the error:

no test specified

What gives? I am in the root project directory and the tests are in my "test" folder. Here is what happens:

localhost:stratum-client-master davea$ npm install
up to date in 0.381s
localhost:stratum-client-master davea$ npm test test/callbacks.js

> [email protected] test /Users/davea/Documents/workspace/stratum-client-master
> echo "Error: no test specified" && exit 1 "test/callbacks.js"

Error: no test specified
sh: line 0: exit: too many arguments
npm ERR! Test failed.  See above for more details.

9 Answers 9

43

Try replacing

"scripts": {
  "test": "mocha"
},

in your package.json.

3
  • I get mocha not found error now
    – toto'
    Oct 19, 2022 at 19:16
  • 1
    'mocha' is not recognized as an internal or external command, Oct 27, 2022 at 18:14
  • 1
    Mocha needs to be installed first before use, thus please run the below command npm i mocha or refer to this doc npmjs.com/package/mocha Nov 3, 2022 at 7:16
21

You're outputting exactly what the package.json file was told to output. Take a peek under scripts.

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "int-test": "mocha --require babel-core/register --recursive test"
},

Try int-test, the other command in there.

Update: The package link has changed to the following and mocha should be the default test suite. You can run the other script with npm run bump-version; the original script above can be run with npm run int-test.

"scripts": {
  "test": "mocha --recursive test",
  "bump-version": "npm version patch"
},
2
  • I did try "npm int-test" as their documentaiton recommended but got the error "Usage: npm <command> ... Did you mean one of these? test install-test" so tthen I migrated to what I had above.
    – Dave
    Feb 18, 2018 at 23:46
  • 5
    In order to run a command in the script tag, you must specify the run subcommand. npm run int-test. npm test is just a short-hand for npm run test. It might be a good idea to replace the test command with the int-test so that you can run npm test.
    – trs
    Feb 26, 2018 at 22:02
17

You didn't specify which testing framework you're using such as Jest or Mocha.

In case of Jest, add this in your package.json:

"scripts" : { 
    "test" : "jest" 
 }

In the case of mocha refer to @Divyeshpal's answer.

1
  • Hi, i am using Jasmine frame work, instead of jest what i need to add?
    – Explorer
    Mar 16, 2021 at 18:26
8

The error can be for "exit 1"

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},

Change it to this:

"scripts": {
  "test": "echo \"No test specified\""
},

This change works because exit 1 creates an error.

4

if you are using Jest and enzyme for unit testing and you have a jest.config.json config file, you can update your package.json under scripts to the following:

"scripts":{    
  "test": "jest --config=./jest.config.json --coverage",
}
2

The error can be for "exit 1"

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1"
},

Change it to this:

"scripts": {
  "test": "echo \"No test specified\""
},

This change worked for me because exit 1 created the error.

1

find and make changes in your package.json

"scripts":{ "test":"mocha" }

0

add this on your packages.json file:

"scripts":{
    "test": "mocha --ui tdd tests/callbacks.js",
}

then npm test on the console.

-2

Replace
echo \"Error: no test specified\" && exit 1 in your package.json with mocha.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.