diff --git a/projects/spectator/jest/src/lib/mock.ts b/projects/spectator/jest/src/lib/mock.ts index 95847c2d..71c0019f 100644 --- a/projects/spectator/jest/src/lib/mock.ts +++ b/projects/spectator/jest/src/lib/mock.ts @@ -7,7 +7,7 @@ export type SpyObject = BaseSpyObject & { [P in keyof T]: T[P] & (T[P] ext * @internal */ export function createSpyObject(type: InjectableType, template?: Partial>): SpyObject { - const mock: any = template || {}; + const mock: any = { ...template } || {}; installProtoMethods(mock, type.prototype, () => { const jestFn = jest.fn(); diff --git a/projects/spectator/jest/test/mock.spec.ts b/projects/spectator/jest/test/mock.spec.ts new file mode 100644 index 00000000..ccbd1401 --- /dev/null +++ b/projects/spectator/jest/test/mock.spec.ts @@ -0,0 +1,16 @@ +import { mockProvider } from '@ngneat/spectator/jest'; + +import { WidgetService } from '../../test/widget.service'; + +describe('mockProvider', () => { + it('should not modify the object passed in 2nd argument when running the mock factory', () => { + const customPropertiesAndMethods: Partial> = { + testingProperty: 'overriden' + }; + const { useFactory: factory } = mockProvider(WidgetService, customPropertiesAndMethods); + factory(); + expect(customPropertiesAndMethods).toEqual({ + testingProperty: 'overriden' + }); + }); +});