Junit and Mockito like decorators for jest, just for the fun of it
Usage:
import { when } from 'jest-when';
import { Mock, Test } from 'mockito-decorator';
@Test
export class MyServiceTest {
@Mock(OtherService)
otherService!: OtherService;
aTest() {
const service = new MyService(this.otherService);
beforeEach(() => {
when(this.otherService.doSomething)
.calledWith(someArgument)
.mockReturnValue('world');
});
it('should do something smart', () => {
expect(this.myService.fetch()).toEqual('Hello world');
});
}
anotherTest() {
const service = new MyService(this.otherService);
beforeEach(() => {
when(this.otherService.doSomething)
.calledWith(someArgument)
.mockReturnValue('you');
});
it('should do something smart', () => {
expect(this.myService.fetch()).toEqual('Hello you');
});
}
}