我卡在了最开始的阶段,只需要CLI并捕获其输出。我尝试了两种方法,但都不起作用。
这是我的cli.js:
这是我的 cli.test.js 文件:
无论运行哪个测试,输出结果都是相同的:“不太重要”。
这是我的cli.js:
#!/usr/bin/env node
console.log('Testing...');
process.exit(0);
这是我的 cli.test.js 文件:
test('Attempt 1', () => {
let stdout = require("test-console").stdout;
let output = stdout.inspectSync(function() {
require('./cli.js');
});
expect(output).toBe('Testing...');
});
test('Attempt 2', () => {
console.log = jest.fn();
require('./cli.js');
expect(console.log.calls).toBe(['Testing...']);
});
无论运行哪个测试,输出结果都是相同的:“不太重要”。
$ jest
RUNS bin/cli.test.js
Done in 3.10s.