如何在angular中将内部函数测试成函数?

How to test internal function into function in angular?

我有一个问题要问你们。 测试内部函数是什么方法,我说successCallback和failureCallback; 因为我检查代码覆盖率,那些功能没有覆盖。

onSubmitForm() {
    const name: string = this.newForm.controls.name.value;
    const successCallback = () => {
      this.popupService.popupSuccess();
    };
    const failureCallback = () => {
      this.popupService.popupFailure();
    };
      this.myservice.edit({ name, this.id }, successCallback, failureCallback);
  }

我认为这样的方法可行。

it('should call popupSuccess on success', () => {
  component.onSubmitForm();
  // get the 2nd argument
  const successCallback = mockMyService.edit.calls.mostRecent().args[1];
  successCallback();
  expect(mockPopupService.popupSuccess).toHaveBeenCalled();
});

it('should call popupFailure on failure', () => {
  component.onSubmitForm();
  // get the 3rd argument
  const failCallback = mockMyService.edit.calls.mostRecent().args[2];
  failCallback();
  expect(mockPopupService.popupFailure).toHaveBeenCalled();
});