Node.js v19.1.0 正式发布
Node.js v19.1.0 现已发布,此版本一些更新内容包括:
Notable changes
支持 Node.js 测试运行器上的 function mocking #45326
node:test 模块在测试过程中通过顶层的 mock object 支持 mocking。
test('spies on an object method', (t) => {
const number = {
value: 5,
add(a) {
return this.value + a;
},
};
t.mock.method(number, 'add');
assert.strictEqual(number.add(3), 8);
assert.strictEqual(number.add.mock.calls.length, 1);
});
Linux 上的 fs.watch 递归支持 #45098
fs.watch使用recursive: true选项支持 recursive watch
const watcher = fs.watch(testDirectory, { recursive: true });
watcher.on('change', function(event, filename) {
});
Other notable changes
详情可查看更新说明:https://nodejs.org/en/blog/release/v19.1.0/