Unit test that an action was called in an observer


#1

I’m pretty new to unit testing so bear with me…

I have a simple observer that fires an action based on a boolean. How can I unit test that this.send was called? I want to test the actual action logic in a separate test.

Thanks!


#2

@Bryan_Neill I think one good option would be to use sinon (for an example off the top of my head of its use in a production ember addon see the ember-simple-auth tests). It includes a feature called “spies” which can tell you if a function was called and how many times. There’s an ember-sinon addon too for easy integration.


#3

worked great, thank you!