React testing setup — Jsx transform issue

Fred Wong
fredwong-it
Published in
Feb 22, 2024

--

I tried to setup jest testing with react testing library in the Next.js TypeScript project, and I learnt something today.

Regular testing in .ts file was fine, but I got this error during when ran the test with React component.

I figure out the solution after I google and chatgpt for a while.

This happened when I had the setting in the tsconfig.json

It works after I change to either react or react-jsx

However, if I changed to react , I need to manually add this all over the place import React from 'react' at the beginning of the file, but I didn’t need that when I updated to react-jsx

Here is some explanation from chatgpt, very interesting.

It’s good to capture this and have a detail reading again later on.

--

--