тесты проходят, когда запускаются индивидуально, а не когда работают вместе - PullRequest
0 голосов
/ 25 февраля 2019

У меня есть компонент, для которого я написал два теста.В обоих тестовых случаях используется setTimeout.Я замечаю, что если я запускаю тестовые наборы вместе (в одном describe, тестовые наборы не выполняются, но если я сохраняю их в отдельных describe, тестовые примеры проходят. Почему это так? Два тестовых примера:

fit('should show dialog when message from DialogBoxService is received', () => {
      let dialogBoxService: MockDialogBoxService = TestBed.get(DialogBoxService);

      let dialogServiceContext = new DialogServiceContext(ComponentAndServiceID.QuestionDetailComponent, new QuestionDetailAdditionalInfo())
      /*
      At startup, there is a delay between creation of AppComponent and subscription to DialogService, I have added the test logic in setTimeout to give time for AppComponent to get created and also subscribe.
       */
      setTimeout(() => {
        spyOn(component, 'showDialog');
        dialogBoxService.emitDialogMessage(dialogServiceContext);
        expect(component.showDialog).toHaveBeenCalledWith(dialogServiceContext);
      }, 1000);
    });

    fit('should handle message from AuthGuard service', () => {
      let mockAuthGuard: MockAuthGuard = TestBed.get(AuthGuard);
      spyOn(component, 'handleAuthGuardContextMessage');
      let authGuardContext = new AuthGuardContext('You must sign in first', new AuthGuardAdditionalInfo());
      setTimeout(() => {
        mockAuthGuard.canActivate();
        expect(component.handleAuthGuardContextMessage).toHaveBeenCalledWith(authGuardContext);
      }, 1000);
    });

Я подозреваю, что проблема связана с тем фактом, что оба теста запускают свои expect через 1000 миллисекунд, и один, вероятно, переопределяет другое, но я не уверен, так как не знаю как jasmine планирует разные it

...