angular单元测试private怎么写?

How to write angular Unit test private?

I have a private method

private checkProjectType(el: Project) {
 switch (el.type) {
   case 'Blue':
     return this.handleBlueCheck(el);
   case 'Red':
     return this.handleRedCheck(el);
  }
}

Project is define

export interface Project {
      id?: string;
      cloneId?: string;
      name?: string;
      description?: string;
      type?: string;
      tips?: string;
  }

我没有使用 jasmine 和 Karma 覆盖率的 Unit Test private 的经验。请帮帮我!

首先,我认为你应该通过public测试私有方法。 您可以阅读 here 了解其他方法。 你可以试试:

 it('should trigger of project type is blue', () => {
projectTypeSpy = spyOn(component, 'handleBlueCheck');

component.project = 'Blue';      // if you aware of project type

//call function that calls your private checkProjectType

  expect(projectTypeSpy).toHaveBeenCalledWith(component.project);
});