Skip to content

Commit

Permalink
fix(CopyToClipboard): setup unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wlliaml committed Feb 29, 2024
1 parent 159e890 commit f065093
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/CopyToClipboard/CopyToClipboard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import userEvent from '@testing-library/user-event'
import { describe, expect, it } from 'vitest'

import { render, screen } from '~/common/utils/test'
import { CopyToClipboard } from '~/components'

// setup function
function setup(ui: React.ReactElement) {
return {
user: userEvent.setup(),
...render(ui),
}
}

describe('<CopyToClipboard>', () => {
it('should render CopyToClipboard', async () => {
const textToCopy = 'text to copy'
render(
const { user } = setup(
<CopyToClipboard text={textToCopy}>
{({ copyToClipboard }) => (
<button type="button" onClick={copyToClipboard}>
Expand All @@ -19,7 +28,7 @@ describe('<CopyToClipboard>', () => {
const $button = screen.getByRole('button', { name: 'Copy' })
expect($button).toBeInTheDocument()

$button.click()
await user.click($button)

// FIXME: not support clipboard in jsdom yet
const $toast = screen.getByRole('alert')
Expand Down

0 comments on commit f065093

Please sign in to comment.