admin管理员组文章数量:1334165
According to the Jasmine documentation, the Spy object has a method withArgs ()
spyOn (someObj, 'func'). withArgs (1, 2, 3) .and.returnValue (42);
I can`t find this method in the version adapted for TypeScript. My project was created with angular-cli(ng new), Jasmine was provided from the box. When I try to call the withArgs() method, Visual Code writes to me that this method does not exist in the Spy class...
According to the Jasmine documentation, the Spy object has a method withArgs ()
spyOn (someObj, 'func'). withArgs (1, 2, 3) .and.returnValue (42);
I can`t find this method in the version adapted for TypeScript. My project was created with angular-cli(ng new), Jasmine was provided from the box. When I try to call the withArgs() method, Visual Code writes to me that this method does not exist in the Spy class...
Share Improve this question asked May 11, 2018 at 10:26 Evgeniy MiroshnichenkoEvgeniy Miroshnichenko 1,8632 gold badges20 silver badges32 bronze badges 1-
1
The
@types/jasmine
node package seems to be out of date with the current latest version of Jasmine, 3.1. I've opened an issue on the GitHub repo so it can be addressed. – Jacob Stamm Commented Aug 7, 2018 at 17:33
2 Answers
Reset to default 5It's likely that you are either using an old version of jasmine, or an old version of the jasmine typings library. This particular method was introduced in Jasmine 3.0. Notice that in the Jasmine 2.9 docs, the method does not exist.
All you need to do is update your Jasmine and jasmine typings libraries. Assuming you are using npm, you can do something like this:
npm i -D jasmine@latest jasmine-core@latest @types/jasmine@latest
This updates all jasmine related libraries to their latest version and saves it as devDependencies.
In my case, updating the Jasmine library was no option within the delivery time span due to pany policies. Hence I could not use withArgs.
I solved it by using callFake
and manually check the argument there.Like this:
mockAuthenticationService = jasmine.createSpyObj<AuthenticationService>('authenticationService', ['hasPermission']);
mockAuthenticationService.hasPermission.and.callFake((permission) => {
return (permission === 'MyPermission');
});
本文标签: javascriptJasmineTypeScriptcant find the withArgs () method of the Spy classStack Overflow
版权声明:本文标题:javascript - Jasmine + TypeScript, can`t find the withArgs () method of the Spy class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742364158a2460947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论