I am using NextJS with React Testing Library for component testing. I have a tinymce editor that loads from a CDN. When I tried to render my component which contains the tinymce component with React Testing Library, it failed. This is my Editor.jsx component:
"use client";
import { useRef } from "react";
import { Editor as TinymceEditor } from "@tinymce/tinymce-react";
import { init } from "./tinymceUtils";
import { Box } from "@mui/material";
function Editor() {
return (
<Box height="95vh">
<TinymceEditor
apiKey="my-api-key"
onInit={(_evt, editor) => (editorRef.current = editor)}
initialValue="<p>This is the initial content of the editor.</p>"
init={init}
/>
</Box>
);
}
export default Editor;
And this is my test:
it("Should render <Editor /> with initial text", async function () {
render(<Editor />);
const editorTextarea = await screen.findByTestId(
"tiny-react-editor",
undefined,
{ timeout: 5000 }
);
const iframe = await waitFor(() => editorTextarea.querySelector("iframe"), {
timeout: 10000,
});
console.log(iframe); //It logs null
});
So my test passes but the iframe is null and I cant get it. When I inspect the DOM on my browser, I see that there is a div with role="application" but can't load when I render my component through React Testing Library.