発生している問題を再現する完全に簡略化された例を作成しました。
function TestObj() {
var self = this;
self.getStuff = function(aString, callback) {
// TODO
}
}
describe("server communications", function() {
it("it calls the server", function() {
var obj = new TestObj();
obj.getStuff = jasmine.createSpy();
// swap the above line for this and it makes no difference
// spyOn(obj, "getStuff");
var functionVar = function() {
};
obj.getStuff("hello", functionVar);
expect(obj.getStuff).toHaveBeenCalledWith(
[ "hello", jasmine.any(Function) ]);
});
});
ユニットテストに合格する代わりに、次の出力が得られます。
スパイは[['hello'、<jasmine.any(function Function(){[ネイティブコード]})>]]で呼び出されたと予想されますが、[['hello'、Function]]で呼び出されました
渡した関数(function(){})が実際に関数であると認識されないのはなぜですか?それが期待しているネイティブコードのものは何ですか?他の誰かがjasmine.any(Function)でこの問題を抱えていましたか?ありがとうございました!
編集済み
jasmine.createSpy()の代わりにspyOnを使用してみましたが、違いはありません。私はただ一つの議論を試みました、そしてそれはうまくいきます。最初の文字列引数を導入すると、jasmine.any(Function)が壊れます-アイデアはありますか?