磁带测试在抛出错误测试中以退出代码 1 中止

问题描述

我有一个名为 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.

这不应该发生。磁带应该处理测试的异常。它永远不应该到达节点进程。

我知道,我在这里做错了,但我无法弄清楚是什么。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)