mfrachet
mfrachet

Reputation: 8932

First test with mocha

I mactually trying to run my first unit test with mocha using this code :

var assert = require('assert');


var returnCool = function () {
    return 1;
}

describe("Array contains", function () {
    it('should return-1 when the value is not present', function () {
        returnCool().should.equal(1);
    });
});

The problem is that my code is actually failing everytime. I tried with the sample in mocha website :

describe('Array', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){
      [1,2,3].indexOf(5).should.equal(-1);
      [1,2,3].indexOf(0).should.equal(-1);
    })
  })
})

And it fails too.

What am I doing wrong ?

Thanks for advance

Upvotes: 0

Views: 85

Answers (2)

Michał Dudak
Michał Dudak

Reputation: 5048

You have included an assert library but are using should - style asserts. Either include should.js or use assert-style asserts (assert.equal([1,2,3].indexOf(5), -1))

Upvotes: 1

Munter
Munter

Reputation: 1089

Looks like you are not calling your assertion library. You are currently calling .should() on an integer

Upvotes: 1

Related Questions