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

Tests should verify that callback methods are called with the expected parameters #7

Open
beeman opened this issue Jun 23, 2015 · 1 comment

Comments

@beeman
Copy link
Contributor

beeman commented Jun 23, 2015

This is copied from #5


One of the things that I'm currently looking at is how to properly test the ChangeSet that is passed to the callbacks.

it('should execute the callback after updating watched properties on multiple models', function(done) {
  var self = this;
  var spyStatusParams = { ids: {}, values: {} };
  spyStatusParams.ids[this.joe.id] = 'pending';
  spyStatusParams.ids[this.bilbo.id] = 'pending';
  spyStatusParams.values['pending'] = [this.joe.id.toString(), this.bilbo.id.toString()];

  this.Person.updateAll(null, {status: 'pending', name: 'pending'})
  .then(function(res) {
    expect(self.spyAge).not.to.have.been.called;
    expect(self.spyNickname).not.to.have.been.called;
    expect(self.spyStatus).to.have.been.called;
    expect(self.spyStatus).to.have.been.calledWith(spyStatusParams);
    done();
  })
  .catch(done);
});

This test fails with a message like this as it does not invoke the callback with a ChangeSet, but rather a plain object. I guess I need to change the testsuite above to make spyStatusParams a ChangeSet too, but it's unclear to me how to invoke that method/object. Any ideas are welcome.

AssertionError: expected changeStatus to have been called with arguments 
{
  ids: { 5586d573830590d60c26d689: "pending", 5586d573830590d60c26d68a: "pending" },
  values: { pending: ["5586d573830590d60c26d689", 5586d573830590d60c26d68a] }
}
changeStatus(
[ChangeSet] {
  ids: { 5586d573830590d60c26d689: "pending", 5586d573830590d60c26d68a: "pending" },
  values: { pending: ["5586d573830590d60c26d689", "5586d573830590d60c26d68a"] }
}) => [object Promise]
@mbenedettini
Copy link

I have just submitted a merge request with a new feature for which I have written a couple of tests which make sure that the changeset passed is okay. bcfa307

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

No branches or pull requests

2 participants