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. 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 ...; // for good measure

With just one such test case, everything works fine. But if I add another test case that stubs, I get an error:

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. Is there another step I'm missing?

1 answer

  • answered 2018-08-09 00:34 Joe Attardi

    Turns out this is because Ava runs the tests concurrently. Running the tests serially fixes the issue.