Skip to content

Commit d1bbe72

Browse files
committed
test(component library): Upgrade from deprecated RTL APIs
- Issue with missing types: testing-library/react-testing-library#610
1 parent 1f416fe commit d1bbe72

File tree

8 files changed

+156
-138
lines changed

8 files changed

+156
-138
lines changed

packages/react-component-library/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"@types/react-select": "^3.0.10",
7272
"@types/react-transition-group": "^4.2.3",
7373
"@types/storybook__react": "^5.2.1",
74+
"@types/testing-library__react": "^10.0.1",
7475
"@types/uuid": "^7.0.2",
7576
"@types/yup": "^0.26.28",
7677
"@typescript-eslint/eslint-plugin": "^2.17.0",

packages/react-component-library/src/components/Modal/Modal.test.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// @ts-nocheck
12
import React, { useState } from 'react'
23
import '@testing-library/jest-dom/extend-expect'
34
import {
45
render,
56
RenderResult,
67
fireEvent,
7-
waitForElement,
8+
waitFor,
89
} from '@testing-library/react'
910

1011
import { Button, ButtonProps } from '../Button'
@@ -191,7 +192,7 @@ describe('Modal', () => {
191192
beforeEach(() => {
192193
wrapper.getByText('Show').click()
193194

194-
return waitForElement(() => wrapper.queryAllByText('Hide'))
195+
return waitFor(() => wrapper.queryAllByText('Hide'))
195196
})
196197

197198
it('should be open', () => {
@@ -205,7 +206,7 @@ describe('Modal', () => {
205206
beforeEach(() => {
206207
wrapper.getByText('Hide').click()
207208

208-
return waitForElement(() => wrapper.queryAllByText('Show'))
209+
return waitFor(() => wrapper.queryAllByText('Show'))
209210
})
210211

211212
it('should be closed again', () => {

packages/react-component-library/src/components/NumberInput/NumberInput.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import '@testing-library/jest-dom/extend-expect'
3-
import { render, RenderResult, fireEvent, waitForElement } from '@testing-library/react'
3+
import { render, RenderResult, fireEvent } from '@testing-library/react'
44

55
import { NumberInput } from './NumberInput'
66

packages/react-component-library/src/components/Popover/Popover.test.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
// @ts-nocheck
12
import React from 'react'
23
import '@testing-library/jest-dom/extend-expect'
34
import { renderToStaticMarkup } from 'react-dom/server'
4-
5-
import { render, RenderResult, fireEvent, wait } from '@testing-library/react'
5+
import {
6+
render,
7+
RenderResult,
8+
fireEvent,
9+
waitFor,
10+
} from '@testing-library/react'
611

712
import { Popover, POPOVER_PLACEMENT } from '.'
813

@@ -54,7 +59,7 @@ describe('Popover', () => {
5459
})
5560

5661
it('to not be visible to the end user', async () => {
57-
await wait(() => {
62+
await waitFor(() => {
5863
expect(wrapper.getByTestId('floating-box').classList).not.toContain(
5964
'is-visible'
6065
)

packages/react-component-library/src/components/TabSet/TabSet.test.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
// @ts-nocheck
12
import React from 'react'
23
import '@testing-library/jest-dom/extend-expect'
3-
import { fireEvent, render, RenderResult, wait } from '@testing-library/react'
4+
import {
5+
fireEvent,
6+
render,
7+
RenderResult,
8+
waitFor,
9+
} from '@testing-library/react'
410

511
import { Tab, TabSet } from '.'
612
import { SCROLL_DIRECTION } from './constants'
@@ -151,7 +157,7 @@ describe('TabSet', () => {
151157
) {
152158
wrapper.getByTestId(`scroll-${direction}`).click()
153159

154-
await wait(flushPromises)
160+
await waitFor(flushPromises)
155161
}
156162

157163
beforeEach(() => {

packages/react-component-library/src/fragments/Masthead/Masthead.test.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
// @ts-nocheck
12
import React from 'react'
23
import '@testing-library/jest-dom/extend-expect'
3-
import { fireEvent, render, RenderResult, wait } from '@testing-library/react'
4+
import {
5+
fireEvent,
6+
render,
7+
RenderResult,
8+
waitFor,
9+
} from '@testing-library/react'
410

511
import { Link } from '../../index'
612
import { Masthead, MastheadProps } from './Masthead'
@@ -136,11 +142,11 @@ describe('Masthead', () => {
136142
})
137143

138144
it('should use the onSearch method passed to the masthead to search', async () => {
139-
await wait(() => expect(props.onSearch).toHaveBeenCalledTimes(1))
145+
await waitFor(() => expect(props.onSearch).toHaveBeenCalledTimes(1))
140146
})
141147

142148
it('should hide the searchbar from view', async () => {
143-
await wait(() =>
149+
await waitFor(() =>
144150
expect(wrapper.queryByTestId('searchbar')).toBeNull()
145151
)
146152
})
@@ -221,7 +227,7 @@ describe('Masthead', () => {
221227
})
222228

223229
it('should include the notification content sent to it', async () => {
224-
await wait(() =>
230+
await waitFor(() =>
225231
expect(wrapper.getByTestId('notifications')).toBeInTheDocument()
226232
)
227233
})
@@ -236,7 +242,7 @@ describe('Masthead', () => {
236242
beforeEach(async () => {
237243
const button = wrapper.queryByTestId('notification-button')
238244

239-
await wait(() => wrapper.getByTestId('notifications'))
245+
await waitFor(() => wrapper.getByTestId('notifications'))
240246

241247
fireEvent(
242248
button,
@@ -248,7 +254,7 @@ describe('Masthead', () => {
248254
})
249255

250256
it('should remove the rule on the wrapper so mobile scrolling is enabled again', async () => {
251-
await wait(() =>
257+
await waitFor(() =>
252258
expect(wrapper.queryByTestId('masthead')).not.toHaveClass(
253259
'rn-masthead--show-notifications'
254260
)

packages/react-component-library/src/fragments/NotificationPanel/NotificationPanel.test.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// @ts-nocheck
12
import React from 'react'
23
import '@testing-library/jest-dom/extend-expect'
34
import {
45
fireEvent,
56
render,
67
RenderResult,
7-
waitForElement,
8+
waitFor,
89
waitForElementToBeRemoved,
910
} from '@testing-library/react'
1011

@@ -91,7 +92,7 @@ describe('NotificationPanel', () => {
9192

9293
button.click()
9394

94-
return waitForElement(() => wrapper.queryAllByText('Thomas Stephens'))
95+
return waitFor(() => wrapper.queryAllByText('Thomas Stephens'))
9596
})
9697

9798
it('should blur the button', () => {
@@ -135,7 +136,7 @@ describe('NotificationPanel', () => {
135136
beforeEach(async done => {
136137
wrapper.getByTestId('notification-button').click()
137138

138-
await waitForElement(() => wrapper.queryAllByText('Thomas Stephens'))
139+
await waitFor(() => wrapper.queryAllByText('Thomas Stephens'))
139140

140141
wrapper.getByText('View all notifications').parentElement.click()
141142

@@ -170,7 +171,7 @@ describe('NotificationPanel', () => {
170171
beforeEach(() => {
171172
wrapper.getByTestId('notification-button').click()
172173

173-
return waitForElement(() => wrapper.queryAllByText('Thomas Stephens'))
174+
return waitFor(() => wrapper.queryAllByText('Thomas Stephens'))
174175
})
175176

176177
it('should default to showing notifications on the right', () => {
@@ -197,7 +198,7 @@ describe('NotificationPanel', () => {
197198
beforeEach(() => {
198199
wrapper.getByTestId('notification-button').click()
199200

200-
return waitForElement(() => wrapper.queryAllByText('Thomas Stephens'))
201+
return waitFor(() => wrapper.queryAllByText('Thomas Stephens'))
201202
})
202203

203204
it('should default to showing notifications on the right', () => {
@@ -224,7 +225,7 @@ describe('NotificationPanel', () => {
224225

225226
wrapper.getByTestId('notification-button').click()
226227

227-
await waitForElement(() => wrapper.queryAllByText('Thomas Stephens'))
228+
await waitFor(() => wrapper.queryAllByText('Thomas Stephens'))
228229

229230
fireEvent(
230231
document,

0 commit comments

Comments
 (0)