角度测试用例茉莉花

时间:2018-10-03 18:00:27

标签: angular testing jasmine karma-runner

我正在尝试为该超级报表组件编写测试用例,在其中提供了所有必需的服务和路由器,并且在执行测试用例时,不会得到任何结果:没有成功或错误消息。

例如,在这里我收到此消息Executed 0 of 285 DISCONNECTED

describe('SuperReportsComponent', () => {
    let component: SuperReportsComponent;
    let navigationService: NavigationService;
    let appService: AppService;
    let reportService: ReportsService;
    let reportAction = ReportActions;
    let router: Router;
    let route: ActivatedRoute;
    let store: Store<AppState>;
    let fixture: ComponentFixture<SuperReportsComponent>;

    const MockRouter = {
        navigate: jasmine.createSpy('navigate')
    };

    const MockActivatedRoute = {};

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [SuperReportsComponent],
            imports: [NgCircleProgressModule.forRoot({}),
                NgbPopoverModule,
                HeaderModule,
                StoreModule.forRoot(rootReducer),
                HttpModule,
                CommonModule,
                FormsModule,
                NgbModule.forRoot()],
            providers: [
                ReportActions,
                AppService,
                ReportsService,
                NavigationService,
                NotificationService,
                WebsocketService,
                SharedLayoutService,
                SuperdashService,
                {provide: Router, useValue: MockRouter},
                {provide: ActivatedRoute, useValue: MockActivatedRoute}
            ]
        })
            .compileComponents();
    }));

    beforeEach(() => {
        route = TestBed.get(ActivatedRoute);
        router = TestBed.get(Router);
        navigationService = TestBed.get(NavigationService);
        appService = TestBed.get(AppService);
        reportService = TestBed.get(ReportsService);
        reportAction = TestBed.get(ReportActions);
        store = TestBed.get(Store);
        fixture = TestBed.createComponent(SuperReportsComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });

    it('should create', () => {
        expect(component).toBeTruthy();
    });
});

在这里,我模拟了navigation方法,并为其所有服务提供了所需的模块,但是没有得到任何输出。

输出:

Chrome 69.0.3497 (Linux 0.0.0) ERROR
Chrome 69.0.3497 (Linux 0.0.0) ERROR
  Disconnected, because no message in 10000 ms.
Chrome 69.0.3497 (Linux 0.0.0): Executed 0 of 285 DISCONNECTED (10 secs / 0 secs)

我该如何解决这个问题?

0 个答案:

没有答案