timkindberg / jest-when

Jest support for mock argument-matched return values.
MIT License
734 stars 38 forks source link

Print full stack trace if verifyAllWhenMocksCalled fails #106

Closed mircohacker closed 1 year ago

mircohacker commented 1 year ago

Before when a when mock was defined and not called the verifyAllWhenMocksCalled function only printed the exact line, where the mock was defined. This is almost useless when the actual mock definition happens in a function (e.g. because they share the locations with different arguments to the wrapping function).

Now the error message contains the full stack trace through all the call stack frames the mock definition passed.

Also changes the implementation of the test "fails verification check if all mocks were not called with line numbers" to handle long error messages. Before the regex ran into a Catastrophic backtracking error. Now we split the error lines manually and test them one by one with the same regex.

CC: @niklasschildhauer @semssamaras @christophmuth @janseeger

timkindberg commented 1 year ago

Seems good to me! Thank you for taking the time to contribute @mircohacker.

timkindberg commented 1 year ago

Added to v3.6.0, thanks again!