reactjs / reactjs/react.dev

Update react testing doc section for react 18

Đang mở
#5,147 0 bình luận 0 reaction 1 người được giao Xem trên GitHub

@eps1lon đang làm issue này rồi.

Từ ngày 4/10/2022.

Ngôn ngữ chính
JavaScript
Star
11.8k
Fork
7.9k
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
11

Mô tả

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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.