0

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?

wOvalle
  • 87
  • 9

1 Answers1

1

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);
  });
zerkms
  • 249,484
  • 69
  • 436
  • 539
  • Thanks @zerkms, that was exactly what I thougth. According should.js 'true' should not pass the assertion, but in my case it still does. https://github.com/tj/should.js/#true – wOvalle Aug 25 '15 at 00:22
  • 1
    @wOvalle provide some code, we have no idea what "your case" is – zerkms Aug 25 '15 at 00:23
  • The real problem is that the assertion must have with a function (), afer adding the parenthesis everything worked as usual. – wOvalle Aug 25 '15 at 02:30