tal*_*aul 6 javascript jasmine jasmine2.0
Jasmine 2.0如何监听MyFunction并返回?2
我有以下代码,其中第一行出现错误shouldPass:
Error: function MyFunction(){ return 1; }() method does not exist
它似乎使用整个函数作为函数名称
我的文件.js:
MyFunctionToTest = function(){
return MyFunction() + 1;
}
function MyFunction(){ return 1; }
Run Code Online (Sandbox Code Playgroud)
MyFileSpec.js:
describe("myTest", function(){
it("shouldPass", function(){
spyOn("MyFile", MyFunction).and.returnValue(2);
expect(MyFunctionToTest()).toEqual(3)
})
})
Run Code Online (Sandbox Code Playgroud)
您正试图监视匿名/全局函数。你也许可以用间谍重新定义它。
MyFunction = jasmine.createSpy().and.returnValue(2);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13387 次 |
| 最近记录: |