How do I test a single file using Jest

0 votes

I am able to test multiple files using Jest, but I cannot figure out how to test a single file.

I have:

  • Run npm install jest-cli --save-dev
  • Updated package.json: `{ ... "scripts": { "test": "jest" } ... }
  • Written a number of tests.

Running npm test works as expected (currently it runs 14 tests).

How do I test a single file, e.g. test app/foo/__tests__/bar.spec.js?

I have tried running npm test app/foo/__tests__/bar.spec.js (from the project root), but I get the following error:

npm ERR! Error: ENOENT, open '/node_modules/app/foo/tests/bar.spec.js/package.json'
Nov 26, 2020 in Node-js by kartik
• 37,510 points
39,722 views

1 answer to this question.

0 votes

Hii,

All you have to do is chant the magick incantation:

npm test -- SomeTestFileToRun

The standalone -- is *nix magic for marking the end of options, meaning (for NPM) that everything after that is passed to the command being run, in this case jest. As an aside, you can display Jest usage notes by saying

npm test -- --help

Anyhow, use it

npm test -- Foo
answered Nov 26, 2020 by Niroj
• 82,880 points

Related Questions In Node-js

0 votes
1 answer

How do I uninstall a package installed using npm link?

Hello @kartik, The package can be uninstalled using ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,880 points
3,773 views
0 votes
1 answer

How do you run a js file using npm scripts?

Hello @kartik, Try this: { "scripts" : { ...READ MORE

answered Oct 12, 2020 in Node-js by Niroj
• 82,880 points
10,529 views
0 votes
1 answer

How do I install node-sass using VSCode?

Hello @ Ebuka, Here is the following things you ...READ MORE

answered Jul 14, 2020 in Node-js by Niroj
• 82,880 points
5,023 views
0 votes
1 answer

How to provide a mysql database connection in single file in nodejs?

Hello @kartik, You could create a db wrapper ...READ MORE

answered Oct 15, 2020 in Node-js by Niroj
• 82,880 points
8,474 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
21,907 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,880 points
2,690 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
2,561 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,880 points
41,892 views
0 votes
1 answer

How do I install a module globally using npm?

Hello @kartik, I found the output contained the ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,880 points
531 views
0 votes
1 answer

How do I add a custom script to my package.json file that runs a javascript file?

Hello @kartik, I have created the following, and ...READ MORE

answered Jul 16, 2020 in Node-js by Niroj
• 82,880 points
39,837 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP