Closed mikecann closed 6 years ago
@mikecann Does the following workaround work for you?
let service;
beforeEach(() => {
service = createMockInstance(MyService);
});
I decided to rock my own implementation with this gem:
type Constructor<T> = new(...args: any[]) => T;
function createMock<T>(clazz: Constructor<T>): jest.Mocked<T> {
const instance = new clazz();
const o: any = {};
for (var key in Object.getOwnPropertyDescriptors(instance)) o[key] = jest.fn();
for (var key in Object.getOwnPropertyDescriptors(clazz.prototype)) o[key] = jest.fn();
return o;
}
Cheers
Hey,
I might be doing something wrong but it seems like if I call jest.clearAllMocks(); from my code then it doesnt clear the mocks created by this lib?