Repository URL to install this package:
|
Version:
8.0.0 ▾
|
import React from 'react';
import { shallow, mount } from 'enzyme';
import * as copyToClipboard from '../../utils/copyToClipboard';
import CopyLink from './CopyLink';
describe('CopyLink', () => {
it('should match a snapshot', () => {
const component = shallow(
<CopyLink>
<span>Copy Link</span>
</CopyLink>
);
expect(component).toMatchSnapshot();
});
it('should handle click event', () => {
const onCopyText = jest.fn();
copyToClipboard.default = jest.fn(() => true);
const component = mount(
<CopyLink onCopyText={onCopyText} copyText="text to copy">
<span>Copy Link</span>
</CopyLink>
);
component.find('.CopyLink').simulate('click');
expect(copyToClipboard.default).toHaveBeenCalledWith('text to copy', component.instance().hiddenNode);
expect(onCopyText).toHaveBeenCalledWith(true);
});
});