I am new to Next.js but not to React and Jest; this is the first test suite I'm setting up in Next.js.
I have the following (extremely minimal, but this example does cause the error) component I am trying to test:
export default function Thumbnail(src){
return(
<img src={src}/>
);
};
And the following test that is causing an error:
import { render } from '@testing-library/react';
import Thumbnail from './Thumbnail';
describe('Thumbnail', () => {
test('renders ImageThumbnail for images', () => {
render(
<Thumbnail src='test.jpg' />
);
});
});
The error in question is this:
● Test suite failed to run
TypeError: The "original" argument must be of type function. Received an instance of Object
5 |
6 | describe('Thumbnail', () => {
> 7 |
| ^
8 | test('renders ImageThumbnail for images', () => {
9 | render(
10 | <Thumbnail src='test' />
at Object.<anonymous> (node_modules/test-exclude/index.js:5:14)
at Module.call [as require] (node_modules/next/src/server/require-hook.ts:70:26)
at Object.<anonymous> (node_modules/babel-plugin-istanbul/lib/index.js:12:43)
at Module.call [as require] (node_modules/next/src/server/require-hook.ts:70:26)
at _babelPluginIstanbul (node_modules/@jest/transform/build/index.js:52:39)
at ScriptTransformer._instrumentFile (node_modules/@jest/transform/build/index.js:313:18)
at ScriptTransformer._buildTransformResult (node_modules/@jest/transform/build/index.js:376:33)
at ScriptTransformer.transformSource (node_modules/@jest/transform/build/index.js:431:17)
at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/index.js:519:40)
at ScriptTransformer.transform (node_modules/@jest/transform/build/index.js:558:19)
at Object.<anonymous> (src/app/Thumbnail.test.js:7:59)
I started with, as you might imagine, a somewhat more interesting and complex component and ambitions for a test suite, but simplified down to this point in an attempt to track down the error. Evidently, the issue is not with my particular component. I have also tried rendering a normal HTML img tag in the test, that works just fine, so Jest and React Testing Library are doing their jobs just fine. The error message is infuriatingly vague and gets shadowed over in google results by errors with unrelated packages.
Suggestions on what else to try to resolve this error (given that I'm out of component and test code to simplify) or where to find documentation on this would be extremely appreciated.
Update: after a little more tinkering I have a clarification. I did try removing my component and testing with normal HTML elements like img and div, and this worked; after which I put my component back in and found the error again. I did not try (until just now) using just div and img while my Thumbnail module is imported, and that does also fail, even if I never call Thumbnail in my test. Something about the import itself is causing this problem, I believe. I will continue to tinker and provide any updates, but questions/guidance/illumination would be helpful.
I did also connect that "Promisify" which came up in the google results of this error is present in files mentioned in that stack trace; I trust that it's more likely that something is wrong with my setup than with the tools that Next.js and Jest are built on.