Skip to content

Commit e7809dd

Browse files
author
Kent C. Dodds
committed
test: adjust tests for breaking changes
1 parent 898477d commit e7809dd

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

examples/__tests__/mock.react-transition-group.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jest.mock('react-transition-group', () => {
3838

3939
test('you can mock things with jest.mock', () => {
4040
const {getByText, queryByText} = render(<HiddenMessage initialShow={true} />)
41-
expect(getByText('Hello World')).toBeTruthy() // we just care it exists
41+
expect(getByText('Hello world')).toBeTruthy() // we just care it exists
4242
// hide the message
4343
Simulate.click(getByText('Toggle'))
4444
// in the real world, the CSSTransition component would take some time

examples/__tests__/react-context.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {NameContext, NameProvider, NameConsumer} from '../react-context'
99
*/
1010
test('NameConsumer shows default value', () => {
1111
const {getByText} = render(<NameConsumer />)
12-
expect(getByText('My Name Is:')).toHaveTextContent('My Name Is: Unknown')
12+
expect(getByText(/^My Name Is:/)).toHaveTextContent('My Name Is: Unknown')
1313
})
1414

1515
/**
@@ -23,7 +23,7 @@ test('NameConsumer shows value from provider', () => {
2323
</NameContext.Provider>
2424
)
2525
const {getByText} = render(tree)
26-
expect(getByText('My Name Is:')).toHaveTextContent('My Name Is: C3P0')
26+
expect(getByText(/^My Name Is:/)).toHaveTextContent('My Name Is: C3P0')
2727
})
2828

2929
/**
@@ -39,7 +39,7 @@ test('NameProvider composes full name from first, last', () => {
3939
</NameProvider>
4040
)
4141
const {getByText} = render(tree)
42-
expect(getByText('Received:').textContent).toBe('Received: Boba Fett')
42+
expect(getByText(/^Received:/).textContent).toBe('Received: Boba Fett')
4343
})
4444

4545
/**
@@ -52,5 +52,5 @@ test('NameProvider/Consumer shows name of character', () => {
5252
</NameProvider>
5353
)
5454
const {getByText} = render(tree)
55-
expect(getByText('My Name Is:').textContent).toBe('My Name Is: Leia Organa')
55+
expect(getByText(/^My Name Is:/).textContent).toBe('My Name Is: Leia Organa')
5656
})

examples/__tests__/react-router.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('full app rendering/navigating', () => {
4949
// normally I'd use a data-testid, but just wanted to show this is also possible
5050
expect(container.innerHTML).toMatch('You are home')
5151
const leftClick = {button: 0}
52-
Simulate.click(getByText('about'), leftClick)
52+
Simulate.click(getByText(/about/i), leftClick)
5353
// normally I'd use a data-testid, but just wanted to show this is also possible
5454
expect(container.innerHTML).toMatch('You are on the about page')
5555
})

examples/__tests__/shallow.react-transition-group.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ test('you can mock things with jest.mock', () => {
4141
{in: true, ...defaultProps},
4242
context,
4343
)
44-
Simulate.click(getByText('toggle'))
44+
Simulate.click(getByText(/toggle/i))
4545
expect(CSSTransition).toHaveBeenCalledWith(
4646
{in: true, ...defaultProps},
4747
expect.any(Object),

src/__tests__/forms.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ test('login form submits', () => {
3636
<Login onSubmit={handleSubmit} />,
3737
)
3838

39-
const usernameNode = getByLabelText('username')
40-
const passwordNode = getByLabelText('password')
39+
const usernameNode = getByLabelText(/username/i)
40+
const passwordNode = getByLabelText(/password/i)
4141
const formNode = container.querySelector('form')
42-
const submitButtonNode = getByText('submit')
42+
const submitButtonNode = getByText(/submit/i)
4343

4444
// Act
4545
usernameNode.value = fakeUser.username

src/__tests__/stopwatch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const wait = time => new Promise(resolve => setTimeout(resolve, time))
4242
test('unmounts a component', async () => {
4343
jest.spyOn(console, 'error').mockImplementation(() => {})
4444
const {unmount, getByText, container} = render(<StopWatch />)
45-
Simulate.click(getByText('start'))
45+
Simulate.click(getByText('Start'))
4646
unmount()
4747
// hey there reader! You don't need to have an assertion like this one
4848
// this is just me making sure that the unmount function works.

0 commit comments

Comments
 (0)