Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update react testing doc section for react 18 #5147

Open
edmundsj opened this issue Oct 4, 2022 · 0 comments
Open

Update react testing doc section for react 18 #5147

edmundsj opened this issue Oct 4, 2022 · 0 comments
Assignees

Comments

@edmundsj
Copy link

edmundsj commented Oct 4, 2022

I cannot, for the life of me, figure out how to adapt the setup/teardown section of the current react documentation to React 18, I cannot find code testing examples on the React website, or anywhere else I have looked for React 18.

I went to this link, and adapted my beforeEach / afterEach functions according to the instructions:

let container = null;
let root = null;
beforeEach(() => {
    container = document.createElement('div');
    root = createRoot(container)
})

afterEach(() => {
    root.unmount()
    container = null;
    root = null;
})

it("renders without a name", () => {
    ...
    root.render(<CreateAccount
        ...
        loginLink={''}/>);

    const nodeList = root.querySelectorAll('input')
    nodeList.forEach((element, index) => {
        expect(element.value).toBe(textArray[index]);
    })
    expect(nodeList.length).toBe(3);
});

However, I get the following error when I try to run my tests:

root.querySelectorAll is not a function

This test works just fine when using the documentation for the older version of React, and when I run container.querySelectorAll(). I tried running container.querySelectorAll() as well, and it returns zero elements. What am I doing wrong here, and where can I find test recipes for React 18?

@eps1lon eps1lon self-assigned this Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants