Get help with testing, discuss unit testing strategies etc.


Post by jumpwake »

Can you give an example of how to use isCalled? I've tried several variations and cannot get a successful pass.

For example, if I have a function that I'm writing a test for called LoadStore()...inside this function, there is another function called ClearStore(...) . I tried doing:


t.isCalled('ClearStore', AdminPanelClass, 'Function: ClearStore was called');

It's failing. The scope should be correct, is there another way I'm supposed to pass in the name of the function? Do I actually have to pass in a reference to the function itself?

Post by mats »

You should supply the instance of the object 'owning' the function that you're checking. If it still fails, please submit a full reduced test case we can inspect.

Post by mats »

For reference/example, please see the Siesta test suite:

siesta\tests\201_function.t.js

Post by jumpwake »

Thanks mats....I actually realized my issue. I was calling isCalled after I called the function to test. You have to have isCalled loaded prior to the test. Works well!

Does this actually mock the function and not allow it to be called?

Post by mats »

No it just wraps it to be able to detect calls.

Post Reply