Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diff not working when comparison is in a callback #55

Open
alexrass opened this issue Apr 26, 2016 · 1 comment
Open

Diff not working when comparison is in a callback #55

alexrass opened this issue Apr 26, 2016 · 1 comment
Assignees

Comments

@alexrass
Copy link

@alexrass alexrass commented Apr 26, 2016

Any chance this could be fixed? When doing a object comparison inside of a callback, instead of displaying a nice diff, all you get is:

WARN: 'Unhandled rejection AssertionError: expected [ Array(1) ] to deeply equal [ Array(1) ]'

Example code:

describe('Some test', () => {
  let sandbox;

  beforeEach(() => {
    sandbox = sinon.sandbox.create();
    sandbox.useFakeServer();
    sandbox.server.autoRespond = true;
  });

  afterEach(() => {
    sandbox.restore();
  });

  it('should run some test with a callback', (done) => {
    const someResponse = [{ some: 'response' }];
    sandbox.server.respondWith('GET', '/a/url', (request) => {
      request.respond(
        200,
        { 'Content-Type': 'application/json' },
        JSON.stringify(someResponse)
      );
    });

    somePromise.then((someCollection) => {
      someCollection.toJSON().should.deep.equal(someResponse);

      done();

      return null;
    });
  });

});

I'm using chaijs for assertions, backbone+marionette, and bluebirdjs for promises.

@4kochi 4kochi self-assigned this Apr 26, 2016
@4kochi
Copy link
Collaborator

@4kochi 4kochi commented May 1, 2016

I am not sure if this is a problem with the reporter itself. I played around with some simple bluebird promises and it works. I also found a stack overflow thread with suggest 2 points.

First to return the promise itself instead of calling done within the promise. And second also return the result of the assertion. Reference (http://stackoverflow.com/questions/30405551/how-to-register-a-failed-mocha-test-on-a-promise)

So your example becomes this:

describe('Some test', () => {
  let sandbox;

  beforeEach(() => {
    sandbox = sinon.sandbox.create();
    sandbox.useFakeServer();
    sandbox.server.autoRespond = true;
  });

  afterEach(() => {
    sandbox.restore();
  });

  it('should run some test with a callback', (done) => {
    const someResponse = [{ some: 'response' }];
    sandbox.server.respondWith('GET', '/a/url', (request) => {
      request.respond(
        200,
        { 'Content-Type': 'application/json' },
        JSON.stringify(someResponse)
      );
    });

    return somePromise.then((someCollection) => {
      return someCollection.toJSON().should.deep.equal(someResponse);
    });
  });
});

But I was not able to run you example because I need more informations to see it up. So if you still have the error it would be nice if you could give me a full working example. That would really help me to reproduce the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.