Angular单元测试代码覆盖范围不包括Ngx-Bootstrap模态订阅

时间:2020-11-07 10:29:07

标签: angular unit-testing jasmine karma-jasmine

我创建了一个获取用户确认的模式,并基于用户确认触发了一些可以正常工作的动作。对于上述情况,我已编写了适用的规范。 但是当我检查代码覆盖率时,模态中的某些代码未被覆盖。我可以在单元测试中覆盖以下代码吗?

enter image description here

规格:

describe('#collectReason', () => {
    it('open reason modal when save to cloud', () => {
      bsModalService.show = (): BsModalRef => {
        return { hide: null, content: { reason: new EventEmitter() }, setClass: null };
      };
      component.collectReason();

      expect(component.modalService.show).toBeTruthy();
    });

    it('display modal message when reason modal is opened', () => {
      bsModalService.show = (): BsModalRef => {
        return { hide: null, content: { reason: new EventEmitter() }, setClass: null };
      };
      const modalRef = { hide: null, content: { reason: new EventEmitter() }, setClass: null };

      const modalMessage = {
        title: 'Enter Reason',
      };

      spyOn(bsModalService, 'show').and.returnValue(modalRef);
      component.collectReason();

      expect(bsModalService.show).toHaveBeenCalledWith(ModalReasonComponent, {
        initialState: { ...modalMessage },
      });
    });
  });

0 个答案:

没有答案
相关问题