Closed joelwatson closed 6 years ago
Yes and no. $useHandler
is called for Model
methods but not at the moment for instance methods. Especially starting with Sequelize 4 style code, this get complicated to split out in a good way for testing. I'm still tackling how to handle that.
That said, the way I do this in my code at the moment is by overriding the update
function on the instance I'm returning. I simply assign it to a mock function that does what I want and use that in my tests.
var myMock = User.build();
myMock.update = function () { /* do stuff */ };
return myMock;
Hope that helps. If you have any more questions I'd be happy to help. I'll try and be quicker on the turn around in the future.
Ah, cool, that works. Thanks, @ktsashes!
Is there a way to add a handler for methods that get called on instances returned from another handler? For example, perhaps I return an array of model instances for findAll, and then one of those instances is later called with update()...can I add a handler for the update() call?