Skip to content

Commit 0c42542

Browse files
committed
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.
1 parent 12b7ebe commit 0c42542

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

projects/spectator/src/lib/mock.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function installProtoMethods<T>(mock: any, proto: any, createSpyFn: Funct
7070
/**
7171
* @publicApi
7272
*/
73-
export function createSpyObject<T>(type: Type<T> | AbstractType<T>, template?: Partial<Record<keyof T, any>>): SpyObject<T> {
73+
export function createSpyObject<T>(type: Type<T> | AbstractType<T>, template?: Partial<T>): SpyObject<T> {
7474
const mock: any = { ...template } || {};
7575

7676
installProtoMethods<T>(mock, type.prototype, name => {
@@ -90,7 +90,7 @@ export function createSpyObject<T>(type: Type<T> | AbstractType<T>, template?: P
9090
/**
9191
* @publicApi
9292
*/
93-
export function mockProvider<T>(type: Type<T> | AbstractType<T>, properties?: Partial<Record<keyof T, any>>): FactoryProvider {
93+
export function mockProvider<T>(type: Type<T> | AbstractType<T>, properties?: Partial<T>): FactoryProvider {
9494
return {
9595
provide: type,
9696
useFactory: () => createSpyObject(type, properties)

projects/spectator/src/lib/spectator-routing/initial-module.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import { RouterStub } from './router-stub';
1414
*/
1515
export function initialRoutingModule<S>(options: Required<SpectatorRoutingOptions<S>>): ModuleMetadata {
1616
const moduleMetadata = initialSpectatorModule(options);
17+
const eventsSubject = new Subject<Event>();
1718

1819
if (options.stubsEnabled) {
1920
moduleMetadata.imports.push(RouterTestingModule);
2021
moduleMetadata.providers.push(
2122
options.mockProvider(RouterStub, {
22-
events: new Subject<Event>(),
23+
events: eventsSubject.asObservable(),
2324
emitRouterEvent(event: Event): void {
24-
this.events.next(event);
25+
eventsSubject.next(event);
2526
},
2627
serializeUrl(): string {
2728
return '/';

0 commit comments

Comments
 (0)