Skip to content

Commit

Permalink
fix: #9666 Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lneumeier-visma committed Jan 19, 2025
1 parent 6f18d20 commit bdfea36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getTestBed } from '@angular/core/testing';

export default (): void => {
const testBed: any = getTestBed();
if (testBed.tearDownTestingModule != null) {
if (testBed.shouldTearDownTestingModule != null && testBed.shouldTearDownTestingModule()) {
testBed.tearDownTestingModule();
}
testBed._instantiated = false;
Expand Down
36 changes: 24 additions & 12 deletions tests/mock-helper-flush-test-bed/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@ import { ngMocks } from 'ng-mocks';
describe('mock-helper-flush-test-bed', () => {
it('should execute tearDownTestingModule', () => {
const testBed: any = getTestBed();
if (testBed.tearDownTestingModule == null) {
testBed._instantiated = true;
ngMocks.flushTestBed();
expect(testBed._instantiated).toBeFalse();
} else {
const spy = spyOn(
testBed,
'tearDownTestingModule',
).and.callThrough();
ngMocks.flushTestBed();
expect(spy).toHaveBeenCalledOnceWith();
}
spyOn(testBed, 'shouldTearDownTestingModule').and.returnValue(
true,
);

const spy = spyOn(
testBed,
'tearDownTestingModule',
).and.callThrough();
ngMocks.flushTestBed();
expect(spy).toHaveBeenCalledOnceWith();
});

it('should not execute tearDownTestingModule', () => {
const testBed: any = getTestBed();
spyOn(testBed, 'shouldTearDownTestingModule').and.returnValue(
false,
);

const spy = spyOn(
testBed,
'tearDownTestingModule',
).and.callThrough();
ngMocks.flushTestBed();
expect(spy).not.toHaveBeenCalled();
});
});

0 comments on commit bdfea36

Please sign in to comment.