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

[React@18] Fix remaining unit tests #207195

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ jest.mock('../../../../sourcerer/containers');
jest.mock('../../open_timeline/use_timeline_status');
jest.mock('react-redux', () => {
const origin = jest.requireActual('react-redux');
const mockDispatch = jest.fn();
return {
...origin,
useDispatch: jest.fn(),
useDispatch: jest.fn(() => mockDispatch),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes

  • [job] [logs] Jest Tests / OpenTimelineButton should open the modal after clicking on the button

The problem was that with React@18 the test started getting to this dispatch call and it failed because instead of a function we mock returned undefined.

};
});
jest.mock('react-router-dom', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,7 @@ export const useTimelineTypes = ({

const onFilterClicked = useCallback(
(tabId: TimelineType, tabStyle: TimelineTabsStyle) => {
setTimelineTypes((prevTimelineTypes) => {
if (prevTimelineTypes !== tabId) {
setTimelineTypes(tabId);
}
return prevTimelineTypes;
});
setTimelineTypes(tabId);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes

  • [job] [logs] Jest Tests / useTimelineTypes timelineFilters set timelineTypes correctly

Given the failed test, it seems there was a genuine runtime bug with React@18. It appears that the behavior of this pattern has changed in React@18 compared to React@17. I suspect that the original logic was lost over several refactorings and there is no need to nest setState in the same setState anymore, but please doublecheck

},
[setTimelineTypes]
);
Expand Down