marchaos / jest-mock-extended

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

Fix TypeError thrown in mockReset/mockClear #81

Closed vinh0604 closed 2 years ago

vinh0604 commented 2 years ago

This patch fixes the bug where TypeError is thrown in mockReset/mockClear when the mock has properties with null or undefined values.

I encounter this bug when using jest-mock-extended along with jest-when (https://github.com/timkindberg/jest-when/blob/master/src/when.js#L204). jest-when internally uses __whenMock__ property to store the mock setup, and assign undefined to this once the mock is reset. Calling mockClear or mockReset after that would throw TypeError exception.