The books chapter on React uses pre version 18 syntax?
I get a bunch of error messages when running the tests on page 259. I tried to do the following:
import React from "react";
import {App} from "./App.jsx";
import {render} from "react-dom";
import { createRoot } from 'react-dom/client';
import {act} from "react-dom/test-utils"
// @ts-ignore
global.IS_REACT_ACT_ENVIRONMENT = true
const container = document.createElement("div");
let root = createRoot(container)
test('renders the h1 header', () => {
act(()=> {
root.render(<App />);
});
const header = document.querySelector("h1");
expect(header.textContent).toBe("Cheesecakes: ")
});
But I get null passed to the header so the test fails.
If you could point me int he right direction that would be awesome.
Yes
On Mon, 9 May, 2022, 07:25 John Williams, @.***> wrote:
I get a bunch of error messages when running the tests on page 259. I tried to do the following:
import React from "react"; import {App} from "./App.jsx"; import {render} from "react-dom"; import { createRoot } from 'react-dom/client'; import {act} from "react-dom/test-utils"
// @ts-ignore global.IS_REACT_ACT_ENVIRONMENT = true const container = document.createElement("div"); let root = createRoot(container)
test('renders the h1 header', () => { act(()=> { root.render(<App />); }); const header = document.querySelector("h1"); expect(header.textContent).toBe("Cheesecakes: ")
});
But I get null passed to the header so the test fails.
If you could point me int he right direction that would be awesome.
— Reply to this email directly, view it on GitHub https://github.com/lucasfcosta/testing-javascript-applications/issues/27, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHG7CMWPCVCHFMOBOPEJNLVJBV73ANCNFSM5VMY6SMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>
is it possible to get any update on this?
Hey John, can you provide some more detail about the error you're seeing?