Node.js 如何在单元测试中涵盖arrow函数?
Node.js 如何在单元测试中涵盖arrow函数?,node.js,angular,typescript,unit-testing,jasmine,Node.js,Angular,Typescript,Unit Testing,Jasmine,this.service=()=>{--statements--> 上述声明将使用jasmine单元测试在angular中进行测试。 我能得到一些建议吗 it(“应该服务调用”,()=>{//我想在这里像component.service一样调用arrow函数。?用什么来代替“?”。})这是一个函数,所以您可以立即调用它: 例如: interface Service { fun: () => string; } class Component { constructor
this.service=()=>{--statements-->
上述声明将使用jasmine单元测试在angular中进行测试。
我能得到一些建议吗
it(“应该服务调用”,()=>{//我想在这里像component.service一样调用arrow函数。?用什么来代替“?”。})
这是一个函数,所以您可以立即调用它:
例如:
interface Service {
fun: () => string;
}
class Component {
constructor() {
this.service = () => {
return {
fun: () => 'hello'
};
};
}
service: () => Service;
}
称之为:
const component = new Component();
const service = component.service();
const message = service.fun();
// or in one line:
const message = new Component().service().fun();
component.service()
Not Working选项可用:call、bind、apply…。应该可以工作,请注意删除的点=>
。不是component.service。(
,只是component.service()
this.service.fun=()=>{}
现在我想调用fun,现在它通过了错误fun不是一个函数
谢谢,伙计,我解决了这个问题。