如何在 angular 的单元测试中覆盖箭头函数?

How to cover arrow functions in unit testing in angular?

this.service = () => { -- statements -- }

以上语句将在angular中使用茉莉花单元测试进行测试。 我可以得到一些建议吗?

it("should service call",()=>{ // i want to call the arrow function here like component.service.? what to use in place of '?'. })

它是一个函数,因此您可以立即调用它:

示例:

 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();
 

Typescript playground example