所以我更新到了 React 18,现在我收到了大量的行为警告以及失败的测试。
版本:
反应:18.2.0
反应-dom:18.2.0
笑话:29.3.1
笑话环境-jsdom:29.3.1
ts-笑话:29.0.3
打字稿:4.9.4
console.error 警告:测试中对 ProductPrice 的更新未包含在 act(...) 中。
测试时,导致 React 状态更新的代码应包装到 act(...) 中:
我通过将断言或我的主要渲染方法包装在await waitFor(() => {}.
我应该有更好的方法来修复这些测试吗?这是一个示例测试,通过以下更改从失败变为通过...在我升级到 React 18 和相应的 React-testing-library + jest 版本之前,以下失败的测试已通过
-------------以下测试失败--------------
async function findPlpHeaderText() {
return screen.findByTestId('plp__header-text');
}
test.only('Sold out products render as expected on store', async () => {
await renderPage({ route: '/boutique/21443255', siteName: 'anonymous-store' });
const headerText = await findPlpHeaderText();
await within(headerText).findByText('Childless boutique');
await screen.findByText('Sold Out');
await screen.findByText('Sold Out. Must Have …Run Code Online (Sandbox Code Playgroud)