Skip to content

Commit

Permalink
test: adjust tests for breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed May 6, 2018
1 parent 898477d commit e7809dd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/__tests__/mock.react-transition-group.js
Expand Up @@ -38,7 +38,7 @@ jest.mock('react-transition-group', () => {

test('you can mock things with jest.mock', () => {
const {getByText, queryByText} = render(<HiddenMessage initialShow={true} />)
expect(getByText('Hello World')).toBeTruthy() // we just care it exists
expect(getByText('Hello world')).toBeTruthy() // we just care it exists
// hide the message
Simulate.click(getByText('Toggle'))
// in the real world, the CSSTransition component would take some time
Expand Down
8 changes: 4 additions & 4 deletions examples/__tests__/react-context.js
Expand Up @@ -9,7 +9,7 @@ import {NameContext, NameProvider, NameConsumer} from '../react-context'
*/
test('NameConsumer shows default value', () => {
const {getByText} = render(<NameConsumer />)
expect(getByText('My Name Is:')).toHaveTextContent('My Name Is: Unknown')
expect(getByText(/^My Name Is:/)).toHaveTextContent('My Name Is: Unknown')
})

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

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

/**
Expand All @@ -52,5 +52,5 @@ test('NameProvider/Consumer shows name of character', () => {
</NameProvider>
)
const {getByText} = render(tree)
expect(getByText('My Name Is:').textContent).toBe('My Name Is: Leia Organa')
expect(getByText(/^My Name Is:/).textContent).toBe('My Name Is: Leia Organa')
})
2 changes: 1 addition & 1 deletion examples/__tests__/react-router.js
Expand Up @@ -49,7 +49,7 @@ test('full app rendering/navigating', () => {
// normally I'd use a data-testid, but just wanted to show this is also possible
expect(container.innerHTML).toMatch('You are home')
const leftClick = {button: 0}
Simulate.click(getByText('about'), leftClick)
Simulate.click(getByText(/about/i), leftClick)
// normally I'd use a data-testid, but just wanted to show this is also possible
expect(container.innerHTML).toMatch('You are on the about page')
})
Expand Down
2 changes: 1 addition & 1 deletion examples/__tests__/shallow.react-transition-group.js
Expand Up @@ -41,7 +41,7 @@ test('you can mock things with jest.mock', () => {
{in: true, ...defaultProps},
context,
)
Simulate.click(getByText('toggle'))
Simulate.click(getByText(/toggle/i))
expect(CSSTransition).toHaveBeenCalledWith(
{in: true, ...defaultProps},
expect.any(Object),
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/forms.js
Expand Up @@ -36,10 +36,10 @@ test('login form submits', () => {
<Login onSubmit={handleSubmit} />,
)

const usernameNode = getByLabelText('username')
const passwordNode = getByLabelText('password')
const usernameNode = getByLabelText(/username/i)
const passwordNode = getByLabelText(/password/i)
const formNode = container.querySelector('form')
const submitButtonNode = getByText('submit')
const submitButtonNode = getByText(/submit/i)

// Act
usernameNode.value = fakeUser.username
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/stopwatch.js
Expand Up @@ -42,7 +42,7 @@ const wait = time => new Promise(resolve => setTimeout(resolve, time))
test('unmounts a component', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {})
const {unmount, getByText, container} = render(<StopWatch />)
Simulate.click(getByText('start'))
Simulate.click(getByText('Start'))
unmount()
// hey there reader! You don't need to have an assertion like this one
// this is just me making sure that the unmount function works.
Expand Down

0 comments on commit e7809dd

Please sign in to comment.