[英]How to cover arrow functions in unit testing in angular?
this.service = () => { -- statements -- }
The above statement is to be tested using jasmine unit testing in angular.上面的语句要使用 angular 中的 jasmine 单元测试进行测试。 Can i get some suggestions for that?
我能得到一些建议吗?
it("should service call",()=>{ // i want to call the arrow function here like component.service.? what to use in place of '?'. })
It is a function so you call it immediately:它是一个 function 所以你立即调用它:
example:例子:
interface Service {
fun: () => string;
}
class Component {
constructor() {
this.service = () => {
return {
fun: () => 'hello'
};
};
}
service: () => Service;
}
Calling it:调用它:
const component = new Component();
const service = component.service();
const message = service.fun();
// or in one line:
const message = new Component().service().fun();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.