From 9c7cb7c3eb4eec2d9ec8fa55b3048b3ce90eb2bc Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Tue, 21 Apr 2026 22:02:03 +0200 Subject: [PATCH] test(reminders): move TestBed.inject after overrideProvider Calling TestBed.inject(MockStore) in beforeEach instantiated the test module, so the subsequent TestBed.overrideProvider(MAT_DIALOG_DATA) in createComponent threw "Cannot override provider when the test module has already been instantiated" across all 7 destroy-cleanup specs. Move the store inject and dispatch spy into createComponent, after the override runs, so TestBed stays un-instantiated until the per-test MAT_DIALOG_DATA value is registered. --- .../dialog-view-task-reminders.component.spec.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/features/tasks/dialog-view-task-reminders/dialog-view-task-reminders.component.spec.ts b/src/app/features/tasks/dialog-view-task-reminders/dialog-view-task-reminders.component.spec.ts index a606dc89c0..b94b70304d 100644 --- a/src/app/features/tasks/dialog-view-task-reminders/dialog-view-task-reminders.component.spec.ts +++ b/src/app/features/tasks/dialog-view-task-reminders/dialog-view-task-reminders.component.spec.ts @@ -545,6 +545,11 @@ describe('DialogViewTaskRemindersComponent destroy clears unhandled deadline rem ): DialogViewTaskRemindersComponent => { TestBed.overrideProvider(MAT_DIALOG_DATA, { useValue: { reminders } }); taskServiceSpy.getByIdsLive$.and.returnValue(of(storeTasks)); + // TestBed becomes instantiated on the first inject/createComponent call, + // after which overrideProvider throws. Resolve the store here — after the + // override — rather than in beforeEach so the override still applies. + store = TestBed.inject(MockStore); + dispatchSpy = spyOn(store, 'dispatch').and.callThrough(); const fixture = TestBed.createComponent(DialogViewTaskRemindersComponent); return fixture.componentInstance; }; @@ -587,9 +592,6 @@ describe('DialogViewTaskRemindersComponent destroy clears unhandled deadline rem TranslateStore, ], }).compileComponents(); - - store = TestBed.inject(MockStore); - dispatchSpy = spyOn(store, 'dispatch').and.callThrough(); }); it('dispatches clearDeadlineReminder on ngOnDestroy for an unhandled deadline reminder', () => {