Is this an issue with deep matching/object identity?

AssertionError: expected <BN: 204fce5e3e25026110000000> to equal <BN: 204fce5e3e25026110000000>

It seems strange that chai.should seems to work fine with the same vars:

// works

// doesn't work
assert.equal(supplyCap, _cap);

Change this:

assert.equal(supplyCap, _cap);

To this:

assert.equal(supplyCap.toString(), _cap.toString());
| improve this answer | |
  • Makes sense. This is because there is some internal difference between the objects? – errata Jan 25 at 17:49
  • 1
    @errata: I think that assert.equal just uses ==, and since you're passing two different objects, it fails. You can verify my conjecture by calling assert.equal(supplyCap, supplyCap) and see if it passes. – goodvibration Jan 25 at 19:18
  • interesting point.. thx again – errata Jan 25 at 20:48

Consider using bn-chai if you do it a lot.

Then you can do:

expect(new BN('1')).to.eq.BN(new BN('1'));
expect(new BN('1')).to.eq.BN('1');
expect(new BN('1')).to.eq.BN(1);
| improve this answer | |
  • Ya that does look a lot more pleasant. Perhaps I'll try to migrate. thx! – errata Sep 14 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.