我有signup.js,它包含一个函数名demo()。此函数调用另一个带有参数的YUI库函数:
Y.io('mywrongserver',callbackfunction);我必须测试这个函数,但是我想调用正确的服务器。
Y.io('myrightserver',callbackfunction);这怎么可能呢?我不想更改signup.js中的任何代码,因为它是由开发人员完成的。
我们能利用嘲弄吗?
代码应该是这样的:
signup.js
demo : function(){
alert('i am inside demo');
// Some other stuff
callback = {
on :{
success:function(x,o){
// Some stuff here
}
}
}
// Now call to wrong server
Y.io("mywrongserver", callback); test.js
// Using JSMOCKITO APIs for YUI
testDemo = function(){
// Need to test demo function in signup.js But such that Y.io call to right server
}谢谢
发布于 2013-12-05 03:08:26
答案确实是“是”。我没有用过jsmockto,但我可以用一般的术语来回答它。基本上,您用自己的函数覆盖Y.io,该函数测试Y.io是否传递了正确的参数。
https://stackoverflow.com/questions/17377696
复制相似问题