Skip to content

Instantly share code, notes, and snippets.

@kedar9444
Last active May 22, 2018 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kedar9444/e84478cc92f631a11fdec805a396a202 to your computer and use it in GitHub Desktop.
Save kedar9444/e84478cc92f631a11fdec805a396a202 to your computer and use it in GitHub Desktop.
configuration file, conman for all spec files.
/**
* Reconfigures current test suit to prevent angular components compilation after every test run.
* Forces angular test bed to re-create zone and all injectable services by directly
* changing _instantiated to false after every test run.
* Cleanups all the changes and reverts test bed configuration after suite is finished.
* reference : https://blog.angularindepth.com/angular-unit-testing-performance-34363b7345ba
*/
import { getTestBed, TestBed, ComponentFixture } from '@angular/core/testing';
import { } from 'jasmine';
export const configureTestSuite = () => {
const testBedApi: any = getTestBed();
const originReset = TestBed.resetTestingModule;
TestBed.resetTestingModule();
TestBed.resetTestingModule = () => TestBed;
afterEach(() => {
testBedApi._activeFixtures.forEach((fixture: ComponentFixture<any>) => fixture.destroy());
testBedApi._instantiated = false;
});
afterAll(() => {
TestBed.resetTestingModule = originReset;
TestBed.resetTestingModule();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment