dariosn85/ts-jest-mocker

Throw an error if a unimplemented method is called

Closed this issue · 2 comments

harnyk commented

I noticed that unimplemented methods return undefined, which is not always good, because it is an implicit behavior.

Wouldn't it be better when a method would throw an error with "not implemented" message, if it's not implemented?

Example:

interface Foo {
    bar(): string;
    baz(): number;
}

const foo = mock<Foo>();

// Implementing bar()
foo.bar.mockReturnValue('hello');
// But not implementing baz()

expect(foo.bar()).toBe('hello');

expect(() => foo.baz()).toThrowError('not implemented');
harnyk commented

Just added a PR fixing it

@harnyk than you for the contribution. The suggested change makes sense.