JavaScript JavaScript Unit Testing Behavior Driven Development with Mocha & Chai General Structure of Test Files

Why is npm test throwing error but mocha test works?

When I run npm test after setting up my workspace like the teacher's, it throws this error:

> workspace@1.0.0 test /home/treehouse/workspace                                               
> mocha                                                                                        

  for await (const fixtureFn of fixtureFns) {                                                  

SyntaxError: Unexpected reserved word                                                          
    at createScript (vm.js:80:10)                                                              
    at Object.runInThisContext (vm.js:139:10)                                                  
    at Module._compile (module.js:617:28)                                                      
    at Object.Module._extensions..js (module.js:664:10)                                        
    at Module.load (module.js:566:32)                                                          
    at tryModuleLoad (module.js:506:12)                                                        
    at Function.Module._load (module.js:498:3)                                                 
    at Module.require (module.js:597:17)                                                       
    at require (internal/module.js:11:18)                                                      
    at Object.<anonymous> (/home/treehouse/workspace/node_modules/mocha/lib/cli/one-and-dones.j
npm ERR! Test failed.  See above for more details. 

, but when I run mocha test, it returns

0 passing (2ms)

Why is this happening?

Paul Messmer
Paul Messmer
14,424 Points

Can I see your JS code? Are you calling this in a async function?

I already went on with different videos, using mocha test, so I think my workspace code is ahead of this video's. My code is exactly the same as the teacher's code. Also, it seems like the problem is in mocha.js, which is not my code.

Paul Messmer
Paul Messmer
14,424 Points

Oh ok I'm glad you figured it out!

Yes, also it must've been something with the workspace I had (or maybe my code), because it provided the teacher's code after this section of the course, and when I run npm test it works fine.