From 21d52353ab559259e5ebb08866d768eda4dec5f9 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Wed, 11 Nov 2020 23:17:36 +0800 Subject: [PATCH] test(ActionSheet): update some test cases --- .../test/__snapshots__/index.spec.js.snap | 22 ++++++++ src/action-sheet/test/index.legacy.js | 51 ------------------- src/action-sheet/test/index.spec.js | 49 ++++++++++++++++++ 3 files changed, 71 insertions(+), 51 deletions(-) create mode 100644 src/action-sheet/test/__snapshots__/index.spec.js.snap create mode 100644 src/action-sheet/test/index.spec.js diff --git a/src/action-sheet/test/__snapshots__/index.spec.js.snap b/src/action-sheet/test/__snapshots__/index.spec.js.snap new file mode 100644 index 000000000..4754a0817 --- /dev/null +++ b/src/action-sheet/test/__snapshots__/index.spec.js.snap @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render default slot and match snapshot 1`] = ` + +
+ +
+
+ +
+
Title + + +
+ +
+ Default
+ + +
+
+`; diff --git a/src/action-sheet/test/index.legacy.js b/src/action-sheet/test/index.legacy.js index 6c2b63119..9385d8b76 100644 --- a/src/action-sheet/test/index.legacy.js +++ b/src/action-sheet/test/index.legacy.js @@ -78,45 +78,6 @@ test('click overlay and close', async () => { expect(onClickOverlay).toHaveBeenCalledTimes(1); }); -test('disable lazy-render', () => { - const wrapper = mount(ActionSheet, { - propsData: { - lazyRender: false, - actions: [{ name: 'Option' }, { name: 'Option' }], - cancelText: 'Cancel', - }, - }); - - expect(wrapper.html()).toMatchSnapshot(); -}); - -test('render title and default slot', () => { - const wrapper = mount(ActionSheet, { - propsData: { - value: true, - title: 'Title', - }, - scopedSlots: { - default() { - return 'Default'; - }, - }, - }); - - expect(wrapper.html()).toMatchSnapshot(); -}); - -test('get container', () => { - const wrapper = mount(ActionSheet, { - propsData: { - value: true, - teleport: 'body', - }, - }); - - expect(wrapper.vm.$el.parentNode).toEqual(document.body); -}); - test('close-on-click-action prop', () => { const onInput = jest.fn(); const wrapper = mount(ActionSheet, { @@ -138,18 +99,6 @@ test('close-on-click-action prop', () => { expect(onInput).toHaveBeenCalledWith(false); }); -test('round prop', () => { - const wrapper = mount(ActionSheet, { - propsData: { - value: true, - round: true, - actions: [{ name: 'Option' }], - }, - }); - - expect(wrapper.html()).toMatchSnapshot(); -}); - test('color option', () => { const wrapper = mount(ActionSheet, { propsData: { diff --git a/src/action-sheet/test/index.spec.js b/src/action-sheet/test/index.spec.js new file mode 100644 index 000000000..591061afa --- /dev/null +++ b/src/action-sheet/test/index.spec.js @@ -0,0 +1,49 @@ +import { mount } from '@vue/test-utils'; +import { later } from '../../../test'; +import ActionSheet from '..'; + +test('should render content after disabling the lazy-render prop', async () => { + const wrapper = mount(ActionSheet); + expect(wrapper.find('.van-action-sheet__content').exists()).toBeFalsy(); + + wrapper.setProps({ lazyRender: false }); + await later(); + expect(wrapper.find('.van-action-sheet__content').exists()).toBeTruthy(); +}); + +test('should render default slot and match snapshot', () => { + const wrapper = mount(ActionSheet, { + props: { + show: true, + title: 'Title', + }, + slots: { + default: () => 'Default', + }, + }); + + expect(wrapper.html()).toMatchSnapshot(); +}); + +test('should allow to use the teleport prop', () => { + const root = document.createElement('div'); + mount(ActionSheet, { + propsData: { + show: true, + teleport: root, + }, + }); + + expect(root.querySelector('.van-action-sheet')).toBeTruthy(); +}); + +test('should have "van-popup--round" class when setting the round prop', () => { + const wrapper = mount(ActionSheet, { + propsData: { + show: true, + round: true, + }, + }); + + expect(wrapper.find('.van-popup--round').exists()).toBeTruthy(); +});