fix(DatePicker): fix the value is not updated in time of change event (#11529)

This commit is contained in:
Gavin 2023-02-02 23:33:47 +08:00 committed by GitHub
parent 5412837a87
commit 8bd56f0897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View File

@ -54,7 +54,7 @@ test('should watch modelValue prop and render correctly', async () => {
).toMatchSnapshot(); ).toMatchSnapshot();
}); });
test('should emit change event after dragging options', () => { test('should emit change event after dragging options', async () => {
const wrapper = mount(Area, { const wrapper = mount(Area, {
props: { props: {
areaList, areaList,
@ -67,6 +67,7 @@ test('should emit change event after dragging options', () => {
triggerDrag(columns[2], 0, -100); triggerDrag(columns[2], 0, -100);
columns[2].find('ul').trigger('transitionend'); columns[2].find('ul').trigger('transitionend');
await later();
const params = wrapper.emitted<PickerChangeEventParams[]>('change')?.[0]; const params = wrapper.emitted<PickerChangeEventParams[]>('change')?.[0];
expect(params?.[0].selectedValues).toEqual(['120000', '120100', '120101']); expect(params?.[0].selectedValues).toEqual(['120000', '120100', '120101']);
}); });

View File

@ -160,7 +160,9 @@ export default defineComponent({
}); });
} }
emit('change', extend({ columnIndex }, getEventParams())); nextTick(() => {
emit('change', extend({ columnIndex }, getEventParams()));
});
}; };
const onClickOption = (currentOption: PickerOption, columnIndex: number) => const onClickOption = (currentOption: PickerOption, columnIndex: number) =>

View File

@ -46,7 +46,7 @@ test('should emit cancel event after clicking the cancel button', () => {
]); ]);
}); });
test('should emit change event after draging the column', () => { test('should emit change event after draging the column', async () => {
const wrapper = mount(Picker, { const wrapper = mount(Picker, {
props: { props: {
columns: simpleColumn, columns: simpleColumn,
@ -54,7 +54,7 @@ test('should emit change event after draging the column', () => {
}); });
triggerDrag(wrapper.find('.van-picker-column'), 0, -100); triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
wrapper.find('.van-picker-column ul').trigger('transitionend'); await wrapper.find('.van-picker-column ul').trigger('transitionend');
expect(wrapper.emitted('change')).toEqual([ expect(wrapper.emitted('change')).toEqual([
[ [