sn3ek sn3ek - 1 year ago 97
TypeScript Question

How can I verify that a method has been called with intern test framework?

I'm using The Intern test framework for testing my web application. Now I need to verify that a method has been invoced during a test, but I cannot find any resource which describes that this is possible with e.g. chai!assert or bdd. Can you give me a hint how I can accomplish a verification of a method invocation during test?

Answer Source

There isn't a standard built-in way to do this, but there are several ways to go about it. As @artem suggested, sinon works with Intern and has the ability to stub out methods on objects. If you're testing Dojo code, you can use dojo/aspect to add aspect advice to a method and use that to record that the method was called. You can also just use the plain JavaScript technique of replacing the function of interest with a stub, like var called = false; someObject.myMethod = function () { called = true; };.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download