0

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 ...

  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:

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?

Joe Attardi
  • 4,381
  • 3
  • 39
  • 41
  • 1
    Possible duplicate of [Problems with ava asynchronous tests when stubbing with sinon](https://stackoverflow.com/questions/37900687/problems-with-ava-asynchronous-tests-when-stubbing-with-sinon) – Mark Aug 09 '18 at 00:35
  • 1
    Yup, you are correct. – Joe Attardi Aug 09 '18 at 00:54

1 Answers1

1

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

Joe Attardi
  • 4,381
  • 3
  • 39
  • 41
  • 1
    This fixes the wrapper issue, but how about the speed, serial tests will slow down the pipeline. It would be good if we can get a fix with parallel flow – Mbanda Apr 06 '23 at 10:55