我正在使用https://github.com/testing-library/react-hooks-testing-library测试我的组件,但不确定在此测试中状态更改后如何检查我的组件是否已重新渲染
const { container, getAllByText, getAllByRole, queryByLabelText, getByText, getByLabelText } = renderNavBar(
initialState,
dispatchMock,
);
// get all divs
let divs = getAllByRole('div');
.
.
.
const { result, waitForNextUpdate } = renderHook(() => useReducer(Reducer, initialState));
const [ , dispatch ] = result.current;
act(() => {
dispatch({ type: 'SET_ACTIVE_LINK', payload: 'about' });
fireEvent.click(getByText('home'));
});
// get all divs after the state change,
divs = getAllByRole('div'); // <---- this still has the NavBar component with the old state
状态在分派/单击事件后成功更新。我希望能够以新状态重新渲染组件,但它仍显示具有先前状态的原始组件