我有一个名为 GraphNode 的节点模块的磁带测试:
const tape = require('tape');
const GraphNode = require('../lib/graph-node.js');
tape( t => {
t.throws(GraphNode(), new RegExp('tableName'), 'should throw error on initialization without tableName');
t.end()
});
当错误被抛出时,不是将测试视为成功,而是由节点抛出一个完整的异常:
/path/lib/graph-node.js:4
throw new Error('tableName must be provided on initialization');
^
Error: tableName must be provided on initialization
at GraphNode (/path/lib/graph-node.js:4:11)
at Test.<anonymous> (/path/test/graph-node.test.js:7:12)
at Test.bound [as _cb] (/path/node_modules/tape/lib/test.js:91:32)
at Test.run (/path/node_modules/tape/lib/test.js:108:31)
at Test.bound [as run] (/path/node_modules/tape/lib/test.js:91:32)
at Immediate.next (/path/node_modules/tape/lib/results.js:89:19)
at processImmediate (node:internal/timers:464:21)
error Command failed with exit code 1.
那不应该发生。磁带应该处理测试的异常。它永远不应该到达节点进程。
我知道,我在这里做错了,但我就是不知道是什么。