wOvalle
wOvalle

Reputation: 87

should js assertion is wrong?

I'm using should.js && mocha as test framework to build an application.

I'm returning 'true' for an API method and I found out that should.js was accepting everything as true, which is not.

I set up the following test:

describe('Login', function(){

    it('Should login and return true', function(done){
        isTrue().should.be.true;
        done();
    });
});

function isTrue()
{
    return 'false';
}

And Powershell + mocha result was :

PS C:\Dev\project> mocha --grep logi*


  Login
    √ Should login and return true


  1 passing (27ms)

Am I missing something?

Upvotes: 0

Views: 238

Answers (1)

zerkms
zerkms

Reputation: 254886

You forgot to trigger the assertion:

 isTrue().should.be.true();
                         ^--- here

If we check the should.js source code we will see that the only way for the should.be.true to be fulfilled is when the true (a boolean) exactly is returned (which is not the same as 'true' string).

  Assertion.add('true', function() {
    this.is.exactly(true);
  });

Upvotes: 1

Related Questions