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.
This commit is contained in:
Johannes Millan 2026-04-21 22:02:03 +02:00
parent 30550efa34
commit 9c7cb7c3eb

View file

@ -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', () => {