nodeunit 捕获错误时如何显示完整的堆栈跟踪?例如,我的测试是抛出:
✔ event delete - basic
✔ delete - errors
Fatal error: undefined is not a function
如何让 nodeunit 告诉我在哪里undefined
被调用为函数?
nodeunit 捕获错误时如何显示完整的堆栈跟踪?例如,我的测试是抛出:
✔ event delete - basic
✔ delete - errors
Fatal error: undefined is not a function
如何让 nodeunit 告诉我在哪里undefined
被调用为函数?
问题在于 grunt-contrib-nodeunit:它将原始 nodeunit 消息修改为不太有用的东西。我在这里创建了一个问题。
简而言之,我使用 grunt-contrib-nodeunit 生成的输出如下所示:
user@desktop:~/bug_test$ grunt
Running "nodeunit:all" (nodeunit) task
test.js
Fatal error: undefined is not a function
普通的 nodeunit 给出了更有用的错误信息:
user@desktop:~/bug_test$ nodeunit test.js
test.js
FAILURES: Undone tests (or their setups/teardowns):
- testSomethingElse
To fix this, make sure all tests call test.done()
而且,如问题所示,当有一个堆栈可以共享时,grunt-contrib-nodeunit 有时会隐藏它。
请注意,报告者的选择(grunt、默认或最小)没有任何区别。
解决方案是每当您收到不太有用的错误消息时,始终直接使用 nodeunit 运行您的测试。可能有新的信息。