Angular 4 Error: No provider for ChildrenOutletContexts in Karma-Jasmine Test

前端 未结 1 1120
攒了一身酷
攒了一身酷 2020-12-29 05:24

My Angular application is working properly, but I am keep getting Karma error when I run ng test command. I have attached app component, spec, module and html a

相关标签:
1条回答
  • 2020-12-29 05:45

    Based on the clue provided by @John, I imported RouterTestingModule instead of importing RouterModule and APP_BASE_HREF. So, the following modification in app.component.spec.ts worked!

    import { TestBed, async } from '@angular/core/testing';
    import { FormsModule } from '@angular/forms';
    import { RouterTestingModule } from '@angular/router/testing';
    
    import { AppComponent } from './app.component';
    import { DashboardComponent } from './modules/dashboard/dashboard.component';
    
    describe('AppComponent', () => {
      beforeEach(async(() => {
        TestBed.configureTestingModule({
          imports: [
            RouterTestingModule 
            FormsModule
          ],
          declarations: [
            AppComponent,
            DashboardComponent
          ]
        }).compileComponents();
      }));
    
    0 讨论(0)
提交回复
热议问题