我正在使用 Tape.js 在节点 js 中学习单元测试,到目前为止,我只发现测试一个函数返回的结果很有用,但是如果一个回调被准确地调用了 n 次呢?
我有这个函数调用回调函数 n 次:
const repeatCallback = (n, cb) => {
for (let i = 0; i < n; i++) {
cb();
}
}
module.exports = repeatCallback;
和磁带测试:
const repeatCallback = require('./repeatCallback.js');
const test = require('tape');
test('repeat callback tests', (t) => {
t.plan(3);
repeatCallback(3, () => {console.log('callack called');})
});
我得到了错误:not ok 1 plan != count
如何在测试中更新计数以匹配已调用的次数?
谢谢