Skip to content

Instantly share code, notes, and snippets.

@ppg
Created August 8, 2017 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppg/d46758f39cb172b83a834ae5007672d7 to your computer and use it in GitHub Desktop.
Save ppg/d46758f39cb172b83a834ae5007672d7 to your computer and use it in GitHub Desktop.
Demonstration of deep matching issues with errors
'use strict';
const chai = require('chai');
const expect = chai.expect;
const err1 = new Error('test error');
const err2 = new Error('test error');
it('should match exact errors', function() {
expect(err1).to.equal(err1);
});
it('should NOT match exact different errors', function() {
expect(err1).not.to.equal(err2);
});
it('should deep match different errors', function() {
expect(err1).to.deep.equal(err2);
});
@ppg
Copy link
Author

ppg commented Aug 8, 2017

$ node --version
v6.11.2
$ npm list --depth=0
(redacted)
├── chai@4.1.1
├── mocha@3.5.0
├── mongoose@4.11.6
├── sinon@2.4.1
└── sinon-chai@2.12.0

$ mocha error.js 


  ✓ should match exact errors
  ✓ should NOT match exact different errors
  1) should deep match different errors

  2 passing (9ms)
  1 failing

  1)  should deep match different errors:

      AssertionError: expected [Error: test error] to deeply equal [Error: test error]
      + expected - actual

      
      at Proxy.assertEqual (node_modules/chai/lib/chai/core/assertions.js:1020:19)
      at Proxy.methodWrapper (node_modules/chai/lib/chai/utils/addMethod.js:57:25)
      at Context.<anonymous> (error.js:18:24)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment