Skip to content

Instantly share code, notes, and snippets.

@lai32290
Created September 23, 2020 21:31
Show Gist options
  • Save lai32290/ad2c6ee3ab9cfb0a5114f1e57708980e to your computer and use it in GitHub Desktop.
Save lai32290/ad2c6ee3ab9cfb0a5114f1e57708980e to your computer and use it in GitHub Desktop.
// __tests__/accordion.rtl.js
import '@testing-library/jest-dom/extend-expect'
import React from 'react'
import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import Accordion from '../accordion'
test('can open accordion items to see the contents', () => {
const hats = {title: 'Favorite Hats', contents: 'Fedoras are classy'}
const footware = {
title: 'Favorite Footware',
contents: 'Flipflops are the best',
}
render(<Accordion items={[hats, footware]} />)
expect(screen.getByText(hats.contents)).toBeInTheDocument()
expect(screen.queryByText(footware.contents)).not.toBeInTheDocument()
userEvent.click(screen.getByText(footware.title))
expect(screen.getByText(footware.contents)).toBeInTheDocument()
expect(screen.queryByText(hats.contents)).not.toBeInTheDocument()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment