[英]Sinon stub error: “Attempted to wrap post which is already wrapped” even though I'm restoring
I have a set of Ava tests using Sinon for stubs. 我有一组将Sinon用于存根的Ava测试。 I have several test cases like this one: 我有几个像这样的测试用例:
test('makes a post request', t => {
const postStub = sinon.stub(request, 'post').resolves({ foo: 'bar' });
... some test stuff ...
request.post.restore(); // for good measure
postStub.restore();
});
With just one such test case, everything works fine. 仅使用一个这样的测试用例,一切就可以正常工作。 But if I add another test case that stubs request.post
, I get an error: 但是,如果我添加另一个存根request.post
测试用例,则会出现错误:
Attempted to wrap post which is already wrapped
I don't know why I'm getting this error, though. 不过,我不知道为什么会收到此错误。 After all, I am calling restore
on the stub. 毕竟,我在存根上调用了restore
。 Is there another step I'm missing? 我还缺少其他步骤吗?
Turns out this is because Ava runs the tests concurrently. 事实证明,这是因为Ava同时运行测试。 Running the tests serially fixes the issue. 依次运行测试可解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.