tj / should.js

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

\t | equal check throws, although there's no difference shown #92

Closed buschtoens closed 11 years ago

buschtoens commented 11 years ago

I was doing the tests on my badge and this error caught my attention. should.js doesn't show which part of the string is unequal.

excerpt of test.js

function fixture(name) {
    return fs.readFileSync(path.join(__dirname, "fixtures", name), "utf8").replace(/\r/g, '');
}
badge(500, { subtitlePos: "right" }).should.equal(fixture("positioning.svg"));

I think should.js complains about \r or \n, but it isn't shown.

buschtoens commented 11 years ago

Comparing the length of the strings shows, that one is two chars longer. But I can't see where those extra chars are. They're not at the start and not at the end.

buschtoens commented 11 years ago
var expected = fixture("positioning.svg");
var found = [], diff = 0;
badge(500, { subtitlePos: "right" }).split("").forEach(function(actualChar, index) {
    var expectedChar = expected.charAt(index+diff);
    if(actualChar != expectedChar) {
        found.push({ actual: actualChar, expected: expectedChar });
        diff++;
    }
});
console.log(found);
[ { actual: '<', expected: '\t' },
  { actual: '<', expected: '\t' },
  { actual: 'r', expected: '<' },
  { actual: '<', expected: '\t' },
  { actual: 'c', expected: '<' },
  { actual: '<', expected: '\t' },
  { actual: 'p', expected: '<' },
  { actual: '<', expected: '\t' },
  { actual: 'p', expected: '<' },
  { actual: '<', expected: '\t' },
  { actual: 't', expected: '<' },
  { actual: '<', expected: '\t' },
  { actual: 't', expected: '<' },
  { actual: '<', expected: '\t' } ]

Seems like should.js has trouble displaying tabs.

buschtoens commented 11 years ago

My error is fixed now. I accidentally double indented positioning.svg. Nevertheless the issue remains. should.js doesn't highlight errors on tabs.

btd commented 11 years ago

It is mocha issue. Should.js just complain that it is not equal, test runner create diff for you.

So it is better to duplicated issue to mocha.