0

I installed Mocha and Shouldjs using

npm install -g mocha

npm install -g should

to test my Angular app. I copied a test from here, which reads as follows:

describe('addition', function () {
 it('should add 1+1 correctly', function (done) {
   var onePlusOne = 1 + 1;
   onePlusOne.should.equal(2);
   // must call done() so that mocha know that we are... done.
   // Useful for async tests.
   done();
 });
});

However, when I run the test using

mocha mytest.js

I get this error:

  addition
    1) should add 1+1 correctly


  0 passing (7ms)
  1 failing

  1) addition should add 1+1 correctly:
     TypeError: Cannot call method 'equal' of undefined
      at Context.<anonymous> (C:\wamp\www\myproj\v4\static\src\app\project\overview\overview.spec.js:4:27)
      at Test.Runnable.run (C:\Users\Imray\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:218:15)
      at Runner.runTest (C:\Users\Imray\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:374:10)
      at C:\Users\Imray\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:452:12
      at next (C:\Users\Imray\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:299:14)
      at C:\Users\Imray\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:309:7
      at next (C:\Users\Imray\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:248:23)
      at Object._onImmediate (C:\Users\Imray\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:345:15)

Can anyone see how this can be fixed?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

1 Answers1

0

Looking at the docs they seem to need to wrap primitives in ( ) to get it to work:

https://github.com/shouldjs/should.js

var should = require('should');

(5).should.be.exactly(5).and.be.a.Number;

And also:

Should(5).be.exactly(5)

Would work.

So try changing your code to:

(onePlusOne).should.equal(2);

Peter Ashwell
  • 4,292
  • 2
  • 18
  • 22