According to the Jasmine documentation , Spy对象有一个方法withArgs()
spyOn (someObj, 'func'). withArgs (1, 2, 3) .and.returnValue (42);
我在适配TypeScript的版本中找不到这个方法。我的项目是用 angular-cli(ng new) 创建的,Jasmine 是开箱即用的。当我尝试调用 withArgs() 方法时,Visual Code 写信给我说这个方法在 Spy 类中不存在...
最佳答案
您可能正在使用旧版本的 jasmine,或者旧版本的 jasmine typings 库。 Jasmine 3.0 中介绍了这种特殊方法.请注意,在 Jasmine 2.9 docs , 该方法不存在。
您需要做的就是更新您的 Jasmine 和 jasmine typings 库。假设你正在使用 npm,你可以这样做:
npm i -D jasmine@latest jasmine-core@latest @types/jasmine@latest
这会将所有与 jasmine 相关的库更新到最新版本并将其保存为 devDependencies。
关于javascript - Jasmine + TypeScript,找不到Spy类的withArgs()方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50290263/