From e368139cdfe51892392de8fded5d3ae91fa1fd64 Mon Sep 17 00:00:00 2001 From: tanjinzhou <415800467@qq.com> Date: Tue, 16 Mar 2021 15:39:44 +0800 Subject: [PATCH] test: update test --- components/checkbox/__tests__/group.test.js | 8 ++++++-- components/popconfirm/__tests__/index.test.js | 18 +++++++----------- components/select/index.tsx | 2 +- components/tooltip/__tests__/tooltip.test.js | 5 +++++ components/typography/Base.tsx | 2 +- examples/App.vue | 2 +- package.json | 2 +- 7 files changed, 22 insertions(+), 17 deletions(-) diff --git a/components/checkbox/__tests__/group.test.js b/components/checkbox/__tests__/group.test.js index 7756b42e9..7d69df567 100644 --- a/components/checkbox/__tests__/group.test.js +++ b/components/checkbox/__tests__/group.test.js @@ -1,11 +1,11 @@ import { mount } from '@vue/test-utils'; -import { asyncExpect } from '@/tests/utils'; +import { asyncExpect, sleep } from '@/tests/utils'; import Checkbox from '../index'; import mountTest from '../../../tests/shared/mountTest'; describe('CheckboxGroup', () => { mountTest(Checkbox.Group); - it('should work basically', () => { + it('should work basically', async () => { const onChange = jest.fn(); const wrapper = mount( { @@ -18,12 +18,16 @@ describe('CheckboxGroup', () => { }, ); wrapper.findAll('.ant-checkbox-input')[0].trigger('change'); + await sleep(); expect(onChange).toHaveBeenCalledWith(['Apple']); wrapper.findAll('.ant-checkbox-input')[1].trigger('change'); + await sleep(); expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear']); wrapper.findAll('.ant-checkbox-input')[2].trigger('change'); + await sleep(); expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear', 'Orange']); wrapper.findAll('.ant-checkbox-input')[1].trigger('change'); + await sleep(); expect(onChange).toHaveBeenCalledWith(['Apple', 'Orange']); }); diff --git a/components/popconfirm/__tests__/index.test.js b/components/popconfirm/__tests__/index.test.js index c2ecbdbe1..26fbc1315 100644 --- a/components/popconfirm/__tests__/index.test.js +++ b/components/popconfirm/__tests__/index.test.js @@ -1,5 +1,5 @@ import { mount } from '@vue/test-utils'; -import { asyncExpect } from '@/tests/utils'; +import { asyncExpect, sleep } from '@/tests/utils'; import Popconfirm from '..'; function $$(className) { return document.body.querySelectorAll(className); @@ -73,12 +73,12 @@ describe('Popconfirm', () => { }, 1000); }); - it('should not open in disabled', async () => { + fit('should not open in disabled', async () => { const popconfirm = mount( { render() { return ( - + click me ); @@ -86,13 +86,9 @@ describe('Popconfirm', () => { }, { sync: false }, ); - - await asyncExpect(() => { - popconfirm.find('span').trigger('click'); - }, 1000); - await asyncExpect(() => { - const popup = popconfirm.vm.$refs.popconfirm.getPopupDomNode(); - expect(popup).toBeFalsy(); - }, 1000); + popconfirm.find('span').trigger('click'); + popconfirm.vm.$refs.popconfirm.$forceUpdate(); + const popup = popconfirm.vm.$refs.popconfirm.getPopupDomNode(); + expect(popup).toBeFalsy(); }); }); diff --git a/components/select/index.tsx b/components/select/index.tsx index 3d4393a8a..c6a9f10fc 100644 --- a/components/select/index.tsx +++ b/components/select/index.tsx @@ -119,7 +119,7 @@ const Select = defineComponent({ ), ); const triggerChange = (...args: any[]) => { - emit('update:value', ...args); + emit('update:value', args[0]); emit('change', ...args); }; return { diff --git a/components/tooltip/__tests__/tooltip.test.js b/components/tooltip/__tests__/tooltip.test.js index 503217954..f2fafbd15 100644 --- a/components/tooltip/__tests__/tooltip.test.js +++ b/components/tooltip/__tests__/tooltip.test.js @@ -16,6 +16,11 @@ describe('Tooltip', () => { mouseEnterDelay: 0, mouseLeaveDelay: 0, onVisibleChange, + // TODO test/util 的bug 没有使用 v-model 同样会改变 + 'onUpdate:visible': () => { + props.visible = this.visible; + this.$forceUpdate(); + }, }; if (this.visible !== undefined) { props.visible = this.visible; diff --git a/components/typography/Base.tsx b/components/typography/Base.tsx index b1bc239ce..8c6c253fa 100644 --- a/components/typography/Base.tsx +++ b/components/typography/Base.tsx @@ -201,8 +201,8 @@ const Base = defineComponent({ function onContentChange(value: string) { const { onChange } = editable.value; if (value !== props.content) { - onChange?.(value); emit('update:content', value); + onChange?.(value); } } diff --git a/examples/App.vue b/examples/App.vue index ea30ba29f..e15daac46 100644 --- a/examples/App.vue +++ b/examples/App.vue @@ -5,7 +5,7 @@