diff --git a/src/action-sheet/test/index.legacy.js b/src/action-sheet/test/index.legacy.js index cfce79b89..fa2fe6945 100644 --- a/src/action-sheet/test/index.legacy.js +++ b/src/action-sheet/test/index.legacy.js @@ -1,4 +1,4 @@ -import { mount, later } from '../../../test'; +import { mount } from '../../../test'; import ActionSheet from '..'; test('callback events', () => { @@ -40,61 +40,3 @@ test('callback events', () => { expect(onSelect).toHaveBeenCalledWith(actions[0], 0); expect(wrapper.html()).toMatchSnapshot(); }); - -test('click overlay and close', async () => { - const onInput = jest.fn(); - const onClickOverlay = jest.fn(); - const div = document.createElement('div'); - - mount({ - template: ` -
- -
- `, - components: { - ActionSheet, - }, - data() { - return { - teleport: () => div, - }; - }, - methods: { - onInput, - onClickOverlay, - }, - }); - - await later(); - - div.querySelector('.van-overlay').click(); - expect(onInput).toHaveBeenCalledWith(false); - expect(onClickOverlay).toHaveBeenCalledTimes(1); -}); - -test('close-on-click-action prop', () => { - const onInput = jest.fn(); - const wrapper = mount(ActionSheet, { - propsData: { - value: true, - actions: [{ name: 'Option' }], - closeOnClickAction: true, - }, - context: { - on: { - input: onInput, - }, - }, - }); - - const option = wrapper.find('.van-action-sheet__item'); - option.trigger('click'); - - expect(onInput).toHaveBeenCalledWith(false); -}); diff --git a/src/action-sheet/test/index.spec.js b/src/action-sheet/test/index.spec.js index ab1d84983..5c7f539c1 100644 --- a/src/action-sheet/test/index.spec.js +++ b/src/action-sheet/test/index.spec.js @@ -115,3 +115,35 @@ test('should render description slot when match snapshot', () => { wrapper.find('.van-action-sheet__description').html() ).toMatchSnapshot(); }); + +test('should close after clicking option if close-on-click-action prop is true', () => { + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + actions: [{ name: 'Option' }], + closeOnClickAction: true, + }, + }); + + const option = wrapper.find('.van-action-sheet__item'); + option.trigger('click'); + + expect(wrapper.emitted('update:show').length).toEqual(1); + expect(wrapper.emitted('update:show')[0][0]).toEqual(false); +}); + +test('should emit click-overlay event and closed after clicking the overlay', async () => { + const onClickOverlay = jest.fn(); + const wrapper = mount(ActionSheet, { + props: { + show: true, + onClickOverlay, + }, + }); + + await later(); + + wrapper.find('.van-overlay').trigger('click'); + expect(wrapper.emitted('update:show')[0][0]).toEqual(false); + expect(onClickOverlay).toHaveBeenCalledTimes(1); +});