I am trying to follow a first example from https://mochajs.org/
Done this
$ npm install -g mocha
Got
C:\Windows\system32>npm install -g mocha npm WARN deprecated [email protected]: Jade has been renamed to pug, please install th e latest version of pug instead of jade npm WARN deprecated [email protected]: graceful-fs version 3 and before will fai l on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possibl e. C:\Users\TestUser\AppData\Roaming\npm\_mocha -> C:\Users\TestUser\AppData\Roamin g\npm\node_modules\mocha\bin\_mocha C:\Users\TestUser\AppData\Roaming\npm\mocha -> C:\Users\TestUser\AppData\Roaming \npm\node_modules\mocha\bin\mocha [email protected] C:\Users\TestUser\AppData\Roaming\npm\node_modules\mocha ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ([email protected]) ├── [email protected] ([email protected]) ├── [email protected] ([email protected], [email protected]) └── [email protected] ([email protected], [email protected], [email protected])
Also installed chai (sorry, I originally forgot to mention it)
C:\Windows\system32>npm install -g chai [email protected] C:\Users\TestUser\AppData\Roaming\npm\node_modules\chai ├── [email protected] ├── [email protected] └── [email protected] ([email protected])
And here is the code
var assert = require('chai').assert; describe('Array', function() { describe('#indexOf()', function () { it('should return -1 when the value is not present', function () { assert.equal(-1, [1,2,3].indexOf(5)); assert.equal(-1, [1,2,3].indexOf(0)); }); }); });
Keep getting
Error: Cannot find module 'chai' at Function.Module._resolveFilename (module.js:325:15) at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object.<anonymous> (c:\git\develop\SendText\test\test2.js:1:76) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10)
What am I doing wrong?
Chai is an assertion library that is mostly used alongside Mocha. It can be used both as a BDD / TDD assertion library for NodeJS and can be paired with any JavaScript testing framework. It has several interfaces that a developer can choose from and looks much like writing tests in English sentences.
What is Chai? Chai is an assertion library, similar to Node's built-in assert . It makes testing much easier by giving you lots of assertions you can run against your code.
Chai HTTP provides an interface for live integration testing via superagent. To do this, you must first construct a request to an application or url. Upon construction you are provided a chainable api that allows you to specify the http VERB request (get, post, etc) that you wish to invoke.
You have installed chai
globally (with -g
option), that's why require
don't find it.
You need to install it locally (on your node_modules
directory), so that require
can find it.
To do so, type:
npm install --save-dev chai
You need to install chai
locally to require it.
npm install chai
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With