lundi 31 août 2020

Cant test copy from 'copy-to-clipboard' with sinon

I'm trying to test my component with Sinon. It seems I can't simulate the click function which is in the TableMenu component. TableMenu.jsx

import copy from 'copy-to-clipboard';

const TableMenu = ({onClick, onHide, rowId}) => (
    <MenuPopover
        onClick={onClick}
        onHide={onHide}>
        <MenuPopover.Item id={1} onClick={() => copy(rowId)} label='Copy'/>
    </MenuPopover>
);

TableMenu.test.js

import copy from 'copy-to-clipboard';
jest.mock('copy-to-clipboard', () => sinon.spy());

it('check method onCopy called', () => {
    const wrapper = shallow(<TableMenu {...props}/>);
    wrapper.find(MenuPopover.Item).last().props().onClick()
    expect(copy.calledOnce).to.eql(true);
});

I'm getting the below error:

Error: Not implemented: window.prompt
    at module.exports (C:\adm\node_modules\jsdom\lib\jsdom\browser\not-implemented.js:9:17)
    at Window.prompt (C:\adm\node_modules\jsdom\lib\jsdom\browser\Window.js:458:7)
    at copy (C:\adm\node_modules\copy-to-clipboard\index.js:58:14)
    at Object.onClick (C:\adm\src\TableMenu/TableMenu.jsx:19:43)
    ...
    ...

TypeError: reselectPrevious is not a function
    at copy (node_modules\copy-to-clipboard\index.js:72:5)
    at Object.onClick (src\TableMenu/TableMenu.jsx:19:43)
    at Context.<anonymous> (src\TableMenu/TableMenu.test.js:62:62)
    at process.topLevelDomainCallback (domain.js:121:23)

Aucun commentaire:

Enregistrer un commentaire