supertest
supertest copied to clipboard
fix: add stacktrace to failed expect function call
Hi! First, thank you for maintaining this great tool 🙂
Issue
When using a function call for the expect assertion, and throwing an error inside this function, the displayed stack trace does not contain information from where the assertion is called. Instead, it only contains the line where the exception is thrown.
This gets problematic when the assertion method is located in a module different from the test suite. In this case, the test suite is not even referenced. This can be verified in the first commit: https://github.com/visionmedia/supertest/commit/b24da855443221dd13c391aae9c4c40c7bd8fe7d (those tests will fail).
Solution
The solution resides in the second commit: https://github.com/visionmedia/supertest/commit/3dba4e9df3f0f84fde1685c249aed3b1da636f05.
As you can see, the wrapAssertFn is starting to look very similar to the _assertFunction. In my opinion, the _assertFunction could be removed altogether. However, I did not venture into this as this would probably be a breaking change, because this method is part of the API despite being marked as internal. Please let me know what you think.