Stuck on 2.2.3 - Running Jest Unit Test

I am following module 2.2.3 on the Foundation Certificate course and get to this bit where it says to run the test using the code “node_modules/jest/bin/jest.js src/tests/exampleComponent.test.js”

When i open the terminal and add that code in, then all it does is open up the exampleComponent.test.js file and place the cursor at the start of that file. I cannot see any test run information anywhere.

What am I doing wrong?

Here is a screenshot of my VS Code with terminal once I have added that code:

1 Like

That is odd behaviour. Not sure what is going on there exactly.

One suggestion would be to try installing jest globally with npm install -g jest and then attempt to run:

jest src/__tests__/exampleComponent.test.js

Try typing it in as well so that no hidden characters are appearing.

1 Like

Thanks Mark. It turned out to be connected with my execution policy. After a bit of reading about that, I found that I had an undefined signature, which meant that it wouldnt let me run any scripts. I then corrected the signature for my currentuser and it has now let me run the test using your suggested code above.

More info can be found here: about Execution Policies - PowerShell | Microsoft Learn

1 Like