refactor(core): Add an ngOnDestroy to GlobalEventDelegation. (#56762)

It seems that this makes test libs that contain > 1 test file pass.

PR Close #56762
This commit is contained in:
Thomas Nguyen
2024-06-28 14:20:50 -07:00
committed by Jessica Janiuk
parent 9cbfc6bf25
commit fdd8fb0e66
2 changed files with 6 additions and 2 deletions
+6 -1
View File
@@ -20,6 +20,7 @@ import {Attribute} from '@angular/core/primitives/event-dispatch';
import {Injectable, InjectionToken, Injector, inject} from './di';
import {RElement} from './render3/interfaces/renderer_dom';
import {EVENT_REPLAY_ENABLED_DEFAULT, IS_EVENT_REPLAY_ENABLED} from './hydration/tokens';
import {OnDestroy} from './interface/lifecycle_hooks';
declare global {
interface Element {
@@ -82,9 +83,13 @@ export const GLOBAL_EVENT_DELEGATION = new InjectionToken<GlobalEventDelegation>
* `provideGlobalEventDelegation` is called.
*/
@Injectable()
export class GlobalEventDelegation {
export class GlobalEventDelegation implements OnDestroy {
private eventContractDetails = inject(JSACTION_EVENT_CONTRACT);
ngOnDestroy() {
this.eventContractDetails.instance?.cleanUp();
}
supports(eventName: string): boolean {
return isSupportedEvent(eventName);
}
@@ -18,7 +18,6 @@ function configureTestingModule(components: unknown[]) {
describe('event dispatch', () => {
let fixture: ComponentFixture<unknown>;
afterEach(() => fixture.debugElement.injector.get(ɵJSACTION_EVENT_CONTRACT).instance?.cleanUp());
it(`executes an onclick handler`, async () => {
const onClickSpy = jasmine.createSpy();