Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/components / src / components / controls / CopyLink / CopyLink.spec.js
Size: Mime:
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);
  });
});