loopback-ds-changed-mixin icon indicating copy to clipboard operation
loopback-ds-changed-mixin copied to clipboard

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

Open beeman opened this issue 9 years ago • 1 comments

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]

beeman avatar Jun 23 '15 22:06 beeman