mikewilliamson
mikewilliamson

Reputation: 24783

AssertionError testing arrays with Mocha

I have what I thought was a pretty uncontroversial test to make sure my initial testing setup is working ok.

import assert from 'assert';
describe('Test', () => {
  it('Arrays', () => {
    assert.equal([], []);
  });
});

The output of the test is pretty mysterious to me.

> mocha --compilers js:babel-register test/*_test.js

  Test
    1) Arrays

  0 passing (29ms)
  1 failing

  1) Test Arrays:

      AssertionError: [] == []
      + expected - actual

      at Context.<anonymous> (basic_test.js:6:12)

npm ERR! Test failed.  See above for more details.

Adjectives fail me. Is there someone who can shed a little light on this.

Upvotes: 0

Views: 1088

Answers (2)

Joost Vunderink
Joost Vunderink

Reputation: 1236

Maybe assert.deepEqual() is what you are looking for?

assert.deepEqual([], []);

Alternatively, you could use the should.js library:

require('should');

var a = 'test';
a.should.equal('test'); // "equal" for primitives

var b = [];
b.should.eql([]); // "eql" for data structures

Upvotes: 2

Paul-Jan
Paul-Jan

Reputation: 17278

I'd hardly call that an uncontroversial test, in what javascript test framework is [] equal to []? Because in vanilla javascript, it definitely isn't.

[] == []
false

[] === []
false

Upvotes: 2

Related Questions