Update react testing doc section for react 18
@eps1lon 已經在處理了。
開始於 2022年10月4日。
- 主要語言
- JavaScript
- 星號
- 11.8k
- 分支
- 7.9k
- 平均合併
- 1 天 11 小時
- 30 天內合併 PR
- 11
描述
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?
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
評估
這個 Issue 還沒有評估資料。