Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e42f4e

Browse files
authored
chore: Fix tests (#1288)
1 parent edb6344 commit 7e42f4e

File tree

5 files changed

+56
-14
lines changed

5 files changed

+56
-14
lines changed

‎jest.config.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const {jest: jestConfig} = require('kcd-scripts/config')
2+
3+
module.exports = Object.assign(jestConfig, {
4+
coverageThreshold: {
5+
...jestConfig.coverageThreshold,
6+
// Full coverage across the build matrix (React versions) but not in a single job
7+
// Ful coverage is checked via codecov
8+
'./src/pure.js': {
9+
// minimum coverage of jobs using different React versions
10+
branches: 97,
11+
functions: 88,
12+
lines: 94,
13+
statements: 94,
14+
},
15+
},
16+
})

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"@testing-library/jest-dom": "^5.11.6",
5454
"chalk": "^4.1.2",
5555
"dotenv-cli": "^4.0.0",
56-
"jest-diff": "^29.4.1",
56+
"jest-diff": "^29.7.0",
5757
"kcd-scripts": "^13.0.0",
5858
"npm-run-all": "^4.1.5",
5959
"react": "^18.0.0",

‎src/__tests__/render.js‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import ReactDOM from 'react-dom'
33
import ReactDOMServer from 'react-dom/server'
44
import {fireEvent, render, screen, configure} from '../'
55

6+
// Needs to be changed to 19.0.0 once alpha started.
7+
const isReactExperimental = React.version.startsWith('18.3.0-experimental')
8+
const isReactCanary = React.version.startsWith('18.3.0')
9+
10+
// Needs to be changed to isReactExperimental || isReactCanary once alpha started.
11+
const testGateReact18 = isReactExperimental ? test.skip : test
12+
613
describe('render API', () => {
714
let originalConfig
815
beforeEach(() => {
@@ -213,27 +220,35 @@ describe('render API', () => {
213220
expect(wrapperComponentMountEffect).toHaveBeenCalledTimes(1)
214221
})
215222

216-
test('legacyRoot uses legacy ReactDOM.render', () => {
223+
testGateReact18('legacyRoot uses legacy ReactDOM.render', () => {
217224
expect(() => {
218225
render(<div />, {legacyRoot: true})
219226
}).toErrorDev(
220-
[
221-
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
222-
],
227+
isReactCanary
228+
? [
229+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://react.dev/link/switch-to-createroot",
230+
]
231+
: [
232+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
233+
],
223234
{withoutStack: true},
224235
)
225236
})
226237

227-
test('legacyRoot uses legacy ReactDOM.hydrate', () => {
238+
testGateReact18('legacyRoot uses legacy ReactDOM.hydrate', () => {
228239
const ui = <div />
229240
const container = document.createElement('div')
230241
container.innerHTML = ReactDOMServer.renderToString(ui)
231242
expect(() => {
232243
render(ui, {container, hydrate: true, legacyRoot: true})
233244
}).toErrorDev(
234-
[
235-
"Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
236-
],
245+
isReactCanary
246+
? [
247+
"Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://react.dev/link/switch-to-createroot",
248+
]
249+
: [
250+
"Warning: ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
251+
],
237252
{withoutStack: true},
238253
)
239254
})

‎src/__tests__/renderHook.js‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import React from 'react'
22
import {renderHook} from '../pure'
33

4+
// Needs to be changed to 19.0.0 once alpha started.
5+
const isReactExperimental = React.version.startsWith('18.3.0-experimental')
6+
const isReactCanary = React.version.startsWith('18.3.0')
7+
8+
// Needs to be changed to isReactExperimental || isReactCanary once alpha started.
9+
const testGateReact18 = isReactExperimental ? test.skip : test
10+
411
test('gives committed result', () => {
512
const {result} = renderHook(() => {
613
const [state, setState] = React.useState(1)
@@ -61,7 +68,7 @@ test('allows wrapper components', async () => {
6168
expect(result.current).toEqual('provided')
6269
})
6370

64-
test('legacyRoot uses legacy ReactDOM.render', () => {
71+
testGateReact18('legacyRoot uses legacy ReactDOM.render', () => {
6572
const Context = React.createContext('default')
6673
function Wrapper({children}) {
6774
return <Context.Provider value="provided">{children}</Context.Provider>
@@ -78,9 +85,13 @@ test('legacyRoot uses legacy ReactDOM.render', () => {
7885
},
7986
).result
8087
}).toErrorDev(
81-
[
82-
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
83-
],
88+
isReactCanary
89+
? [
90+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://react.dev/link/switch-to-createroot",
91+
]
92+
: [
93+
"Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot",
94+
],
8495
{withoutStack: true},
8596
)
8697
expect(result.current).toEqual('provided')

‎tests/toWarnDev.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SOFTWARE.
2929
/* eslint-disable func-names */
3030
/* eslint-disable complexity */
3131
const util = require('util')
32-
const jestDiff = require('jest-diff').default
32+
const jestDiff = require('jest-diff').diff
3333
const shouldIgnoreConsoleError = require('./shouldIgnoreConsoleError')
3434

3535
function normalizeCodeLocInfo(str) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /