mockito-decorator
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i mockito-decorator

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

5.92 kB

Total Files

4

Last publish

Collaborators

  • dev.iam