tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 194 forks source link

confusion with optional arguments #168

Closed mcranston18 closed 10 years ago

mcranston18 commented 10 years ago

I'm trying to enact the optional error description but am having trouble. I'm using Mocha and trying to execute the following:

describe('a test ', function() {
    it('will perform a test', function() {
        var num1 = 1;
        var num2 = 2;
        num1.should.eql(num2, 'or the test will fail and this error should be appear');
    });
})

The test will fail as expected, but I won't see the the error message.

btd commented 10 years ago

Actually bug in mocha. With this PR, which was done only for chaijs, ruin partially other libraries. If we see there mocha begin expect message in format: contex:message. Which should.js does not use of course and weird thing that it just reject all other formats with match ? ... : ''.

@travisjeffery correct me if i am wrong, but it really looks like mocha bug. Easy fix to replace line 191 from:

msg = match ? '\n      ' + color('error message', match[1]) : '';

to:

msg = '\n      ' + color('error message', match ? match[1]: msg);

Result before: 2014-01-18 15 28 01

and result after: 2014-01-18 15 28 52

btd commented 10 years ago

@travisjeffery Thanks.

travisjeffery commented 10 years ago

:+1: