angular.io icon indicating copy to clipboard operation
angular.io copied to clipboard

More documentation for TestBed.overrideModule

Open wheelerlaw opened this issue 9 years ago • 0 comments

I'm currently working around a bug with Jasmine/Angular/Karma/the universe by using TestBed.overrideModule() to override a module that is causing trouble in my Jasmine tests.

@NgModule({
    imports: [],
    declarations: [],
    providers: [ConfirmationService],
    bootstrap: []
})
class MockDialog {
    constructor(private service: ConfirmationService) {
    }
}

describe('Return File Parameter Component Test', () => {
    beforeEach(() => {
        TestBed.configureTestingModule({
            declarations: [ReturnFileParameterComponent, HtmlUserFriendlyTimePipe, Html24HourDatePipe, DayOfWeekPipe],
            providers: [
                ...
                ConfirmationService,
                ...
            ],
            imports: [
                ConfirmDialogModule,
                ...
            ]
        })
            .overrideModule(ConfirmDialogModule, {
                set: MockDialog
            })
            .compileComponents();

But I don't know if what I am doing is right! So this is a feature request for more documentation on TestBed.overrideModule() because currently there is none (or at least nothing that is helpful).

wheelerlaw avatar Jan 23 '17 18:01 wheelerlaw