启用sinon fakeServer日志

问题描述 投票:0回答:1

我正在运行几个测试,我正在使用sinon假服务器模拟http调用:

import sinon from 'sinon';
...
const fakeServer = sinon.fakeServer.create();
fakeServer.respondWith('POST', '/myapp/myendpoint/pathparam', [201, { 'Content-Type': 'application/json' }, myPayload]);
...

然而假的服务器返回一个未找到的错误:[404, { }, (empty string)]

我无法弄清楚出了什么问题。

有没有办法激活某种日志,告诉我发生了什么?

在浏览sinon's documentation之后,我找不到任何有关日志或调试标志的信息。

javascript testing mocking automated-tests sinon
1个回答
0
投票

检查sinon后,我发现它不包含假的服务器,但它暴露了nise/fake-server/

然后我去了nise,我最终找到了跟踪行为的方法:

logger: function () {
    // no-op; override via configure()
},

因此,要在虚假服务器中启用日志,您唯一需要做的就是在创建虚假服务器时指定行为:

fakeServer = sinon.fakeServer.create({logger: str => console.log('Fake server', str)});
© www.soinside.com 2019 - 2024. All rights reserved.