You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ngMocks.flushTestBed() function prevents the cleanup-code in angular's TestBed.tearDownTestingModule function. As a result, unit test execution is much slower, because of duplicated, not cleaned up shared host styles (and maybe other objects). (3000 tests, 3-4 minutes instead of 1-1,5 minutes)
// If the module ref has already been destroyed, we won't be able to get a test renderer.
if (this._testModuleRef === null) {
return;
}
// Resolve the renderer ahead of time, because we want to remove the root elements as the very
// last step, but the injector will be destroyed as a part of the module ref destruction.
const testRenderer = this.inject(TestComponentRenderer);
try {
this._testModuleRef.destroy();
} catch (e) {
if (this.shouldRethrowTeardownErrors()) {
throw e;
} else {
console.error('Error during cleanup of a testing module', {
component: this._testModuleRef.instance,
stacktrace: e,
});
}
} finally {
testRenderer.removeAllRootElements?.();
}
Description of the bug
ngMocks.flushTestBed()
function prevents the cleanup-code in angular's TestBed.tearDownTestingModule function. As a result, unit test execution is much slower, because of duplicated, not cleaned up shared host styles (and maybe other objects). (3000 tests, 3-4 minutes instead of 1-1,5 minutes)An example of the bug
ngMocks.flushTestBed()
called from https://github.com/help-me-mom/ng-mocks/blob/master/libs/ng-mocks/src/lib/common/ng-mocks-global-overrides.ts#L56 sets the_testModuleRef
tonull
(https://github.com/help-me-mom/ng-mocks/blob/master/libs/ng-mocks/src/lib/mock-helper/mock-helper.flush-test-bed.ts#L7)
This prevents the cleanup of the test module.
https://github.com/angular/angular/blob/main/packages/core/testing/src/test_bed.ts#L735
Link:
Expected vs actual behavior
Workaround tests.ts:
Add
angular/angular#31834 (comment)
Possible fix in ng-mocks (mock-helper.flush-test-bed.ts)
The text was updated successfully, but these errors were encountered: