import { fireEvent } from '@testing-library/react'; import copy from 'copy-to-clipboard'; import { simpleRender } from '../../.jest/test-utils'; import { Copyable } from './Copyable'; jest.mock('copy-to-clipboard'); describe('Copyable', () => { it('renders an icon', () => { expect(() => simpleRender()).not.toThrow(); }); it('copies the text to the clipboard', () => { jest.useFakeTimers(); const { getByText } = simpleRender(baz qux); const button = getByText('baz qux'); fireEvent.click(button); expect(copy).toHaveBeenCalledWith('foo bar', undefined); jest.runAllTimers(); }); });