2

1signup.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 
}

ありがとう

4

1 に答える 1