Skip to content
Snippets Groups Projects
Commit 3fc01df1 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-3563 fix tests and new mocking function

parent a24ad607
No related branches found
No related tags found
No related merge requests found
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();
});
});
...@@ -47,16 +47,6 @@ export function mock<T>(service: Type<T>): Mock<T> { ...@@ -47,16 +47,6 @@ export function mock<T>(service: Type<T>): Mock<T> {
return mockValue; 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) { function isFunctionDescriptor(prototype: object) {
return (key: string) => { return (key: string) => {
const descriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key); const descriptor: PropertyDescriptor = Object.getOwnPropertyDescriptor(prototype, key);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment