From 0c42542d015488d2bc3f6adf1a540df2e3c813dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Gr=C3=BCnwald?= Date: Tue, 16 May 2023 14:34:30 +0200 Subject: [PATCH] fix(spectator): make mock template type safe (#607) BREAKING CHANGE: introducing type safety for the template values in createSpyObject and mockProvider. This might cause breaking builds because the compiler will find issues hidden until now. --- projects/spectator/src/lib/mock.ts | 4 ++-- .../spectator/src/lib/spectator-routing/initial-module.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/projects/spectator/src/lib/mock.ts b/projects/spectator/src/lib/mock.ts index 52fe8ed6..10860cc7 100644 --- a/projects/spectator/src/lib/mock.ts +++ b/projects/spectator/src/lib/mock.ts @@ -70,7 +70,7 @@ export function installProtoMethods(mock: any, proto: any, createSpyFn: Funct /** * @publicApi */ -export function createSpyObject(type: Type | AbstractType, template?: Partial>): SpyObject { +export function createSpyObject(type: Type | AbstractType, template?: Partial): SpyObject { const mock: any = { ...template } || {}; installProtoMethods(mock, type.prototype, name => { @@ -90,7 +90,7 @@ export function createSpyObject(type: Type | AbstractType, template?: P /** * @publicApi */ -export function mockProvider(type: Type | AbstractType, properties?: Partial>): FactoryProvider { +export function mockProvider(type: Type | AbstractType, properties?: Partial): FactoryProvider { return { provide: type, useFactory: () => createSpyObject(type, properties) diff --git a/projects/spectator/src/lib/spectator-routing/initial-module.ts b/projects/spectator/src/lib/spectator-routing/initial-module.ts index 785cfb7f..9c51bf7a 100644 --- a/projects/spectator/src/lib/spectator-routing/initial-module.ts +++ b/projects/spectator/src/lib/spectator-routing/initial-module.ts @@ -14,14 +14,15 @@ import { RouterStub } from './router-stub'; */ export function initialRoutingModule(options: Required>): ModuleMetadata { const moduleMetadata = initialSpectatorModule(options); + const eventsSubject = new Subject(); if (options.stubsEnabled) { moduleMetadata.imports.push(RouterTestingModule); moduleMetadata.providers.push( options.mockProvider(RouterStub, { - events: new Subject(), + events: eventsSubject.asObservable(), emitRouterEvent(event: Event): void { - this.events.next(event); + eventsSubject.next(event); }, serializeUrl(): string { return '/';