diff --git a/alfa-client/libs/test-utils/src/lib/mocking.spec.ts b/alfa-client/libs/test-utils/src/lib/mocking.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8367a68aacb534b442db66e4aef7f3126ef979e --- /dev/null +++ b/alfa-client/libs/test-utils/src/lib/mocking.spec.ts @@ -0,0 +1,26 @@ +import { Mock, mock } from '@alfa-client/test-utils'; + +describe('mock', () => { + class TestService { + methodTestService() {} + } + + class ExtendedService extends TestService { + prop: string = 'test'; + methodExtendedService() {} + } + + const mockedService: Mock<ExtendedService> = mock(ExtendedService); + + it('should mock methods of a class', () => { + expect(mockedService.methodTestService).toBeDefined(); + }); + + it('should mock methods of inherited class', () => { + expect(mockedService.methodExtendedService).toBeDefined(); + }); + + it('should not mock non-function properties', () => { + expect(mockedService.prop).toBeUndefined(); + }); +}); diff --git a/alfa-client/libs/test-utils/src/lib/mocking.ts b/alfa-client/libs/test-utils/src/lib/mocking.ts index a719f7c6b56b0ed0495b8d8970ecf0cc7f6d6ed5..3a382bde3fc0ec4311a209d6c1b1390d6fa99cf4 100644 --- a/alfa-client/libs/test-utils/src/lib/mocking.ts +++ b/alfa-client/libs/test-utils/src/lib/mocking.ts @@ -47,16 +47,6 @@ export function mock<T>(service: Type<T>): Mock<T> { return mockValue; } -export function mock2<T>(service: Type<T>): Mock<T> { - return <Mock<T>>Object.getOwnPropertyNames(service.prototype).reduce( - (mockValue, key) => ({ - ...mockValue, - [key]: jest.fn(), - }), - <any>{}, - ); -} - function isFunctionDescriptor(prototype: object) { return (key: string) => { const descriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key);