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 / utils / copyToClipboard.test.js
Size: Mime:
"use strict";

var _copyToClipboard = _interopRequireDefault(require("./copyToClipboard"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

beforeAll(function () {
  document.createRange = function () {};

  document.execCommand = function () {};

  document.getSelection = function () {
    return {
      getRangeAt: function getRangeAt() {}
    };
  };
});
test('checking if text is copied', function () {
  var spyFunc = jest.fn();
  var spyCreateRange = jest.fn(function () {
    var obj = {};

    obj.selectNodeContents = function () {};

    return obj;
  });
  Object.defineProperty(global.document, 'execCommand', {
    value: spyFunc
  });
  Object.defineProperty(global.document, 'createRange', {
    value: spyCreateRange
  });
  Object.defineProperty(window, 'getSelection', {
    value: function value() {
      return {
        removeAllRanges: function removeAllRanges() {},
        addRange: function addRange() {}
      };
    }
  });
  var parent = document.createElement('div');
  (0, _copyToClipboard["default"])('test url', parent);
  expect(spyFunc).toHaveBeenCalledWith('copy');
});