React Foundations·Practice drills 3

Drill 6: Teach it — Testing React components

Explain the example to someone who has never seen it.

Intermediate 5 min read Lesson 65 of 300 Challenge included
What you will be able to do
  • Explain the example to someone who has never seen it.

Practice task

Explain the example to someone who has never seen it.

SearchForm.test.tsxTSX
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { vi } from 'vitest'
import SearchForm from './SearchForm'

test('submits the typed query', async () => {
  const user = userEvent.setup()
  const onSearch = vi.fn()

  render(<SearchForm onSearch={onSearch} />)

  await user.type(screen.getByLabelText('Search lessons'), 'hooks')
  await user.click(screen.getByRole('button', { name: 'Search' }))

  expect(onSearch).toHaveBeenCalledWith('hooks')
})
Your turn

Write your answer

Easy

Explain the example to someone who has never seen it.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 65 of 300 · 0% of course