Skip to content

Commit

Permalink
chore: Adjust tests to workaround 18.3.0 bug (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Apr 26, 2024
1 parent d143f46 commit f6a1677
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"jest-diff": "^29.7.0",
"kcd-scripts": "^13.0.0",
"npm-run-all": "^4.1.5",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react": "^18.3.0",
"react-dom": "^18.3.0",
"rimraf": "^3.0.2",
"typescript": "^4.1.2"
},
Expand Down
3 changes: 0 additions & 3 deletions src/__tests__/stopwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class StopWatch extends React.Component {
const sleep = t => new Promise(resolve => setTimeout(resolve, t))

test('unmounts a component', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {})
const {unmount, container} = render(<StopWatch />)
fireEvent.click(screen.getByText('Start'))
unmount()
Expand All @@ -52,6 +51,4 @@ test('unmounts a component', async () => {
// if it's not, then we'll call setState on an unmounted component
// and get an error.
await sleep(5)
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
})
9 changes: 9 additions & 0 deletions tests/shouldIgnoreConsoleError.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ module.exports = function shouldIgnoreConsoleError(format) {
// Ignore it too.
return true
}
if (
format.startsWith(
'Warning: `ReactDOMTestUtils.act` is deprecated in favor of `React.act`.',
)
) {
// This is a React bug in 18.3.0.
// Versions with `ReactDOMTestUtils.ac` being deprecated, should have `React.act`
return true
}
}
}
// Looks legit
Expand Down

0 comments on commit f6a1677

Please sign in to comment.