2

When I run a test code using React testing library with MSW, I got an error

buffer.js:210
throw new ERR_INVALID_ARG_TYPE('target', ['Buffer', 'Uint8Array'], target);
^

TypeError [ERR_INVALID_ARG_TYPE]: The "target" argument must be an instance of Buffer or Uint8Array. Received null
at _copy (buffer.js:210:11)
at Buffer.copy (buffer.js:768:12)
at Request.<anonymous> (/Users/.../node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:864:11)
at Request.emit (events.js:315:20)
at Gunzip.<anonymous> (/Users/.../node_modules/request/request.js:1073:12)
at Gunzip.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Gunzip.Readable.push (_stream_readable.js:212:10)
at Gunzip.Transform.push (_stream_transform.js:152:32) {
code: 'ERR_INVALID_ARG_TYPE'
}

There are 6 test functions in a Component.test.tsx file and all functions have similar code like

test('some test..', async () => {
  server.use(
    rest.get('/api/1/..', (req, res, ctx) => {
      return res(ctx.json({...}));
    }),

    rest.get('/api/2/..', (req, res, ctx) => {
      return res(ctx.json({...}));
    }),
  );

  render(<Component />);
  await waitFor(() => screen.getByText(/test test/i));

});

above.

The bigger problem is sometimes the test passes, even though most time it fails.

I tried dividing each test function in a different test file, like component1.test.tsx, component2.test.tsx, ... component6.test.tsx.

And the result was really weird because Jest pass whole files.

I really want to know why the error is happening.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
swk333
  • 21
  • 2
  • I encountered this before, BUT the reason was that I was running the tests on Github Actions, and I have a method that fetches the content on Github – RaenonX May 25 '21 at 23:43
  • I have been seeing this issue intermittently as well. Have you made any progress? How are you able to tell which test is causing the issue? – jered Oct 13 '21 at 17:41

0 Answers0