问题
I try to test a JavaScript function with Jasmine. It looks like this:
show: function(){
this.work();
var mod = new Module();
mod.doSomething();
}
I am now testing if work()
is called in show()
, which is no problem. But then an error occurs in mod.doSomething()
. This makes my test fail although it actually passed. What can I do to prevent mod.doSomething to be called or at least executed. Is there something like callThrough()
for nonused function calls?
The only idea I had was to write a global variable that can be set true or false from everywhere. Then I extend the mod.doSomething()
function for not to be called if this variable is set true. Now I can simply set the variable to true, if I do not want this function to be executed while testing. But I think there must be a better solution. Can anybody help me?
回答1:
this is not testable with "standard" jasmine-practices. the method show()
should take a module as parameter.... then it would be testable with a spy on doSomething()
...
来源:https://stackoverflow.com/questions/29745532/jasmine-test-how-to-call-through-function-that-is-called-in-tested-function