Reputation: 14361
//Using chai & mocha on typescript I'm comparing two arrays:
it('test my function', function () {
let expectedResult = [ '100998', '100999' ];
let res = myFunc();
res.should.deep.equal(expectedResult);
})
but all I get is this response:
AssertionError: expected [ '100998', '100999' ] to equal [ '100998', '100999' ]
What am I doing wrong?
Upvotes: 1
Views: 578
Reputation: 35
You can use expect(res).to.be.deep.equal
like nbkhope mentioned. This worked for me too. But you should be careful with that. You sometimes lose precision by using deep
. Why this is the case is described in this article
Upvotes: 0
Reputation: 7474
Did you try using expect to accomplish the same thing?
const { expect } = require('chai');
// …
expect(res).to.deep.equal(expectedResult);
If that works, then there’s something wrong in how you set up should
. Did you require it like this?
const should = require('chai').should(); // call the function!
If there’s still any problems, then we have to look at the definition of myFunc()
.
Side Note: you should only use let if you are going to change the variable’s value more than once. That does not seem to be the case for you, so I’d suggest you use const
instead.
Upvotes: 1