marchaos / jest-mock-extended

Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
MIT License
810 stars 56 forks source link

Option to have mock methods throw by default #102

Closed rraziel closed 1 year ago

rraziel commented 1 year ago

Hello,

It could be nice having an option that causes any proxied method throw by default until a .mock*() is called on it, something like:

throw new Error(`mock method ${methodName} has not been configured`)

The idea is to avoid forgetting about mocking some return values/etc. and make the test setup less error prone.

I couldn't seem to find any such option in the existing codebase or documentation, but maybe I didn't look hard enough 😄

Great work on this library btw.

marchaos commented 1 year ago

Hey, yeah I've seen this in other mocking libs (https://mockk.io/ for example). Definitely worth considering. There isn't any existing code that does this, FYI.

marchaos commented 1 year ago

this is fixed in https://github.com/marchaos/jest-mock-extended/pull/110