Skip to content

Commit f3ef4f7

Browse files
committed
feat: configureJestSetup
1 parent 87951b5 commit f3ef4f7

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { TestBed, getTestBed, ComponentFixture } from '@angular/core/testing';
2+
import 'jest';
3+
4+
// Ref: https://github.com/angular/angular/issues/12409
5+
export function configureJestSetup() {
6+
const testBedApi: any = getTestBed();
7+
const originReset = TestBed.resetTestingModule;
8+
9+
beforeAll(() => {
10+
TestBed.resetTestingModule();
11+
TestBed.resetTestingModule = () => TestBed;
12+
});
13+
14+
afterEach(() => {
15+
testBedApi._activeFixtures.forEach((fixture: ComponentFixture<any>) => fixture.destroy());
16+
testBedApi._instantiated = false;
17+
});
18+
19+
afterAll(() => {
20+
TestBed.resetTestingModule = originReset;
21+
TestBed.resetTestingModule();
22+
});
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './configure-test-suite';

projects/testing-library/src/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
export * from './lib/models';
66
export * from './lib/testing-library';
7+
export * from './jest-utils';
78
export * from 'dom-testing-library';

src/app/app.component.spec.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { AppComponent } from './app.component';
2-
import { createComponent } from '@angular-extensions/testing-library';
2+
import { createComponent, configureJestSetup } from '@angular-extensions/testing-library';
3+
4+
configureJestSetup();
35

46
test(`matches snapshot`, async () => {
57
const { container } = await createComponent('<app-root></app-root>', {

0 commit comments

Comments
 (0)