1

I'm trying to write a test for a json returned from a promise. I created this simple code so you can try to reproduce:

"use strict";
var chai = require("chai");
chai.should();
var chaiAsPromised = require("chai-as-promised");
var chaiJsonEqual = require('chai-json-equal');
chai.use(chaiAsPromised);
chai.use(chaiJsonEqual);
var expect = chai.expect;

describe('should', function() {

  it('return true because its the same json object', function() {
    var json = {  "foo": "bar" };
    return expect(Promise.resolve(json)).to.eventually.jsonEqual(json);
  });

});

but i get:

  1) should return true because its the same json object:
     AssertionError: expected {} to have the same json representation as { foo: 'bar' }

chai-as-promised and chai-json-equal works seperatly, but not together. Do you guys have a solution for this, workaround or other libraries I can use?

Yaron Yosef
  • 447
  • 3
  • 12
  • Sounds more like a bug you should report in one of the repositories, not ask on SO for a workaround. – Bergi Oct 12 '16 at 21:06

1 Answers1

1

chai-json-equal hasn't been updated for a year now, so i doubt anyone will respond to an issue.

especially when there's an easier solution.

instead of:

return expect(Promise.resolve(json)).to.eventually.jsonEqual(json);

write:

return expect(Promise.resolve(json)).to.eventually.deep.equal(json);

test passes.

Yaron Yosef
  • 447
  • 3
  • 12