简体   繁体   English

Sinon存根错误:即使我正在还原,也“尝试包装已经包装的帖子”

[英]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.

相关问题 诗农警报存根:“试图包装已经包装的警报” - Sinon alert stub: "Attempted to wrap alert which is already wrapped" 尝试在同一文件中第二次使用存根时包装已包装的警报 - Attempted to wrap alert which is already wrapped when using stub the second time in the same filee TypeError:尝试包装已经包装的 - TypeError: Attempted to wrap which is already wrapped 即使只有一个参数,我也会收到“包装的保证不是可迭代的错误” - I'm getting a 'Wrapped promise not iterable error' even though I have only one parameter Chai + Sinon错误:方法已经包装 - Chai + Sinon error: method is already wrapped 尽管在之前的测试中有效,但在测试中似乎根本没有调用 Sinon 存根 - Sinon stub seems to not be called at all in test even though it works in previous test 我正在使用 sinon.stub 方法将我的服务包装在需要一个数组的打字稿中,但是我的模拟数据是一个对象,我该如何解决这个问题 - I am using a sinon.stub method to wrap my service in typescript which expects an array however my mock data is an object how do I fix this 即使我定义了一个字符串,我也收到了一个错误,即使我定义了一个字符串,我也收到了一个错误 - I'm getting an error even though I defined a string and I'm getting an error even though I defined a string 即使我在POST上收到200响应,$ _ POST数据还是空的? - The $_POST data is empty even though I'm getting a 200 response on the POST? 如果单词尚未包装,如何将它们包装到 span 元素中? - How can I wrap words into span elements if they are not already wrapped?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM