Repository URL to install this package:
|
Version:
8.0.0 ▾
|
import copyToClipboard from './copyToClipboard';
beforeAll(() => {
document.createRange = () => {};
document.execCommand = () => {};
document.getSelection = () => ({
getRangeAt: () => {},
});
});
test('checking if text is copied', () => {
const spyFunc = jest.fn();
const spyCreateRange = jest.fn(() => {
const obj = {};
obj.selectNodeContents = () => {};
return obj;
});
Object.defineProperty(global.document, 'execCommand', { value: spyFunc });
Object.defineProperty(global.document, 'createRange', { value: spyCreateRange });
Object.defineProperty(window, 'getSelection', {
value: () => ({ removeAllRanges: () => {}, addRange: () => {} }),
});
const parent = document.createElement('div');
copyToClipboard('test url', parent);
expect(spyFunc).toHaveBeenCalledWith('copy');
});