UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

42 lines 1.36 kB
import React from 'react'; import { shallow } from 'enzyme'; import Button from "./index"; import { jsx as _jsx } from "react/jsx-runtime"; describe('<Button />', () => { it('should render the button', () => { const wrapper = shallow(/*#__PURE__*/_jsx(Button, { children: "My content" })); expect(wrapper).toMatchSnapshot(); expect(wrapper.find('button').length).toBe(1); }); it('should render the button in disabled state', () => { const wrapper = shallow(/*#__PURE__*/_jsx(Button, { disabled: true, children: "My content" })); expect(wrapper).toMatchSnapshot(); expect(wrapper.find('button[disabled]').length).toBe(1); }); it('should trigger the click event', () => { const callback = jest.fn(); const wrapper = shallow(/*#__PURE__*/_jsx(Button, { onClick: callback, children: "My content" })); wrapper.simulate('click'); expect(wrapper).toMatchSnapshot(); expect(callback).toHaveBeenCalled(); }); it('should not trigger the click event when disabled', () => { const callback = jest.fn(); const wrapper = shallow(/*#__PURE__*/_jsx(Button, { disabled: true, onClick: callback, children: "My content" })); wrapper.simulate('click'); expect(wrapper).toMatchSnapshot(); expect(callback).not.toHaveBeenCalled(); }); });