Node.js 运行Jasmine测试时如何查看“console.log”的输出

Node.js 运行Jasmine测试时如何查看“console.log”的输出,node.js,jasmine,console.log,Node.js,Jasmine,Console.log,我开发了一个Node.js模块,并使用Jasmine为其编写单元测试。当调用verbose参数设置为true时,模块使用console.log打印一些执行信息 假设模块如下所示: foo.js 假设我的测试是这样的: foo-spec.js 我通过在终端中键入jasmine来运行测试: $ jasmine 除了我想看到详细的输出外,一切都很好 $ jasmine Returning Hello World 有没有办法让Jasmine做到这一点?好的,我已经找到了一种解决方法。监视控制台.lo

我开发了一个Node.js模块,并使用Jasmine为其编写单元测试。当调用
verbose
参数设置为true时,模块使用
console.log
打印一些执行信息

假设模块如下所示:

foo.js

假设我的测试是这样的:

foo-spec.js

我通过在终端中键入
jasmine
来运行测试:

$ jasmine
除了我想看到详细的输出外,一切都很好

$ jasmine
Returning Hello World

有没有办法让Jasmine做到这一点?

好的,我已经找到了一种解决方法。监视控制台.log以某种方式修补了它

foo-spec.js

不知道为什么,但是
spyOn
正在使日志再次可见。尽管除了调用
callThrough
之外,我并没有用它做任何事情。我最好的猜测是,通过这样做,
console.log
实际上是从Jasmine进程调用的。

您真的需要看到这个吗?在可测试性方面,监视console.log调用不是更好吗?
$ jasmine
$ jasmine
Returning Hello World
const foo = require("path/to/foo")
describe("Foo suite", () => {

    it( "Expect foo to greet", () => {

        //This makes the log visible again from the command line.
        spyOn(console, 'log').and.callThrough();

        expect(foo("World", true)).toBe("Hello World");
    });
});