Created
September 4, 2017 21:35
-
-
Save willgm/54cd36ebc7165ae28d66a14befb8875f to your computer and use it in GitHub Desktop.
Speed up your component's test suite by caching the test module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TestBed, async } from '@angular/core/testing'; | |
import { AppComponent } from './app.component'; | |
import { setUpCachedTestBed } from '../test-utils'; | |
describe('AppComponent', () => { | |
setUpCachedTestBed({ | |
declarations: [ AppComponent ], | |
}); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(AppComponent); | |
component = fixture.componentInstance; | |
fixture.detectChanges(); | |
}); | |
it('should create the app', async(() => { | |
const fixture = TestBed.createComponent(AppComponent); | |
const app = fixture.debugElement.componentInstance; | |
expect(app).toBeTruthy(); | |
})); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TestBed, TestModuleMetadata } from '@angular/core/testing'; | |
const resetTestingModule = TestBed.resetTestingModule; | |
export function setUpCachedTestBed(moduleDef: TestModuleMetadata) { | |
beforeAll(done => { | |
TestBed.resetTestingModule(); | |
TestBed.resetTestingModule = () => TestBed; | |
TestBed.configureTestingModule(moduleDef); | |
TestBed.compileComponents() | |
.then(done).catch(done.fail); | |
}); | |
afterAll(() => TestBed.resetTestingModule = resetTestingModule); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on angular/angular#12409