0
我正在嘗試使用茉莉花做一些基本測試。我使用外部庫&我打算做的是間諜/模擬方法調用庫對象(D3),並確保在D3上調用適當的方法。茉莉花測試外部庫
var d3Spy = jasmine.createSpyObj('d3', ['select']);
spyOn(window, 'd3').andReturn(d3Spy);
expect(d3Spy.select).toHaveBeenCalled();
當在對象上調用'select'時,出現此錯誤。
TypeError: Object function() {
spyObj.wasCalled = true;
spyObj.callCount++;
var args = jasmine.util.argsToArray(arguments);
spyObj.mostRecentCall.object = this;
spyObj.mostRecentCall.args = args;
spyObj.argsForCall.push(args);
spyObj.calls.push({object: this, args: args});
return spyObj.plan.apply(this, arguments);
} has no method 'select'
我在做什麼錯?
你剛纔指出了'我遇到的所有問題'。由於鏈式方法調用,事情變得更加複雜,我已經從您提出的解決方案中恢復過來。現在,我已經停止了對所有方法調用的間諜活動,並且只監視那些重要的方法調用和簡單的鏈式方法調用。 – Andy