进行过暗恋测试

时间:2018-08-14 12:39:51

标签: angular jasmine karma-runner testbed spyon

这是组件测试:

  describe('document.edit component test', () => {

      beforeEach(async(() => {

        TestBed.configureTestingModule({
          imports: [FormsModule],

          schemas: [NO_ERRORS_SCHEMA],
          declarations: [DocumentEditComponent],
          providers: [{provide: AppConfig, useValue: appConfig},
            {provide: DocumentsService, useValue: documentsService},
            {provide: NgbModal, useClass: modalService},
            {provide: ActivatedRoute, useValue: activatedRoute},
            {provide: BaThemeSpinner, useValue: loader},
            {provide: PopupResultService, useValue: popupResultService},
          ],
        }).compileComponents()

        fixture = TestBed.createComponent(DocumentEditComponent);
        component = fixture.componentInstance;
      }))

      tests();
    })

    function tests() {
      it('document.edit component should create', async(() => {
        expect(component).toBeDefined();
      }));

      it("try to leave custom language with invalid form", async(() => {
        const componentService = fixture.debugElement.injector.get(NgbModal);

        let spyObj = spyOn(componentService, "open")
        component.switchDocumentLanguage("ru-Ru", {invalid: true})


        expect(componentService.open).toHaveBeenCalledWith('some arg');
        //expect(spyObj).toHaveBeenCalled()
      }));

    }

运行“ ng测试”后,我收到了这样的消息。

component.switchDocumentLanguage-它是component方法,在某些情况下会调用'componentService'方法'open'

          Chrome 68.0.3440 (Windows 10.0.0): Executed 1 of 2 SUCCESS (0 secs / 0.365 secs)
          Chrome 68.0.3440 (Windows 10.0.0) ERROR
          Disconnected, because no message in 10000 ms.
            Chrome 68.0.3440 (Windows 10.0.0): Executed 1 of 2 DISCONNECTED (10.373 secs / 0.365 secs)
          Chrome 68.0.3440 (Windows 10.0.0) ERROR
          Chro

如果我不使用'toHaveBeenCalledWith'-测试正常

版本:

          "jasmine-core": "2.5.2",
          "jasmine-spec-reporter": "3.2.0",
          "karma": "1.4.1",
          "karma-chrome-launcher": "2.0.0",
          "karma-cli": "1.0.1",
          "karma-coverage-istanbul-reporter": "0.2.0",
          "karma-jasmine": "1.1.0",
          "karma-jasmine-html-reporter": "0.2.2",

谁曾经遇到过类似的事情?

0 个答案:

没有答案