1.0.0 • Published 1 year ago

mockito-decorator v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

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');
        });
    }
}
1.0.0

1 year ago

0.0.1

1 year ago