Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Unit Testing Behavior Driven Development with Mocha & Chai Test Suites and Test Specs (describe and it)

Mocha and Chai in VS Code on local - 'npm test' failing - Disconnect somewhere but I can't figure out where

Hello All,

I've been following along with this course, and all was going well, up until trying to run the 'sanity check' test in this video, and now I'm a bit lost:

  1. With 'npm test', I ran the test.js file, and a test passed, but it displayed code (a 'console.log' statement) that was not from the file created in this video, so I figured that it was displaying this message from a different file (another file by the same name in my 'test' directory).

  2. I removed the file 'main_test.js' containing the 'console.log' statement from my 'test' directory, and copied the file which is updated in this video, into the 'test' directory, also called 'main_test.js' from the main 'battleshipEngineProject' project directory. So now I have a 'main_test.js' file in both the 'battleshipEngineProject' directory (which also contains my 'package.json' and 'test'), and then, if I navigate into 'test' with 'cd test', I also have a 'main_test.js' file in here.

  3. When I run 'npm test', I get the following error messages in the console:

''' $ npm test

battleshipengineprojecttt05_2019@1.0.0 test /Users/henrybrenton/BattleshipEngineProjectTT05_2019 mocha

/Users/henrybrenton/BattleshipEngineProjectTT05_2019/test/main_testLocal.js:1 (function (exports, require, module, __filename, __dirname) { import { expect as chai } from 'chai'; //previously: "var expect = require('chai').expect;" ^

SyntaxError: Unexpected token { at new Script (vm.js:80:7) at createScript (vm.js:274:10) at Object.runInThisContext (vm.js:326:10) at Module._compile (internal/modules/cjs/loader.js:664:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at /usr/local/lib/node_modules/mocha/lib/mocha.js:330:36 at Array.forEach (<anonymous>) at Mocha.loadFiles (/usr/local/lib/node_modules/mocha/lib/mocha.js:327:14) at Mocha.run (/usr/local/lib/node_modules/mocha/lib/mocha.js:804:10) at Object.exports.singleRun (/usr/local/lib/node_modules/mocha/lib/cli/run-helpers.js:207:16) at exports.runMocha (/usr/local/lib/node_modules/mocha/lib/cli/run-helpers.js:300:13) at Object.exports.handler.argv as handler at Object.runCommand (/usr/local/lib/node_modules/mocha/node_modules/yargs/lib/command.js:242:26) at Object.parseArgs as _parseArgs at Object.parse (/usr/local/lib/node_modules/mocha/node_modules/yargs/yargs.js:566:25) at Object.exports.main (/usr/local/lib/node_modules/mocha/lib/cli/cli.js:63:6) at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:10:23) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3) npm ERR! Test failed. See above for more details.

'''

Advice and guidance in learning to resolve this issue (and others like it) would be greatly appreciated - I'm a bit stumped as to the resolution for this!

Many thanks in advance,

Henry