Skip to content

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

@beeman

Description

@beeman

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions