test: add typing for some test cases (#8243)
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import Rate from '..';
|
||||
import { mount, triggerDrag } from '../../../test';
|
||||
import type { DOMWrapper } from '@vue/test-utils';
|
||||
|
||||
function mockGetBoundingClientRect(items) {
|
||||
function mockGetBoundingClientRect(items: DOMWrapper<Element>[]) {
|
||||
items.filter((icon, index) => {
|
||||
icon.element.getBoundingClientRect = () => ({
|
||||
left: index * 25,
|
||||
width: 25,
|
||||
});
|
||||
icon.element.getBoundingClientRect = () =>
|
||||
({
|
||||
left: index * 25,
|
||||
width: 25,
|
||||
} as DOMRect);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
@@ -16,15 +18,15 @@ test('should emit change and update:modelValue event when rate icon is clicked',
|
||||
const item4 = wrapper.findAll('.van-rate__icon')[3];
|
||||
|
||||
item4.trigger('click');
|
||||
expect(wrapper.emitted('change').length).toEqual(1);
|
||||
expect(wrapper.emitted('change')[0][0]).toEqual(4);
|
||||
expect(wrapper.emitted('update:modelValue').length).toEqual(1);
|
||||
expect(wrapper.emitted('update:modelValue')[0][0]).toEqual(4);
|
||||
expect(wrapper.emitted('change')!.length).toEqual(1);
|
||||
expect(wrapper.emitted('change')![0]).toEqual([4]);
|
||||
expect(wrapper.emitted('update:modelValue')!.length).toEqual(1);
|
||||
expect(wrapper.emitted('update:modelValue')![0]).toEqual([4]);
|
||||
|
||||
await wrapper.setProps({ modelValue: 4 });
|
||||
item4.trigger('click');
|
||||
expect(wrapper.emitted('change').length).toEqual(1);
|
||||
expect(wrapper.emitted('update:modelValue').length).toEqual(1);
|
||||
expect(wrapper.emitted('change')!.length).toEqual(1);
|
||||
expect(wrapper.emitted('update:modelValue')!.length).toEqual(1);
|
||||
});
|
||||
|
||||
test('should not emit change and update:modelValue event when rate is not changed', () => {
|
||||
@@ -49,8 +51,8 @@ test('should allow half rate when using allow-half prop', () => {
|
||||
|
||||
const item4 = wrapper.findAll('.van-rate__icon--half')[3];
|
||||
item4.trigger('click');
|
||||
expect(wrapper.emitted('change')[0][0]).toEqual(3.5);
|
||||
expect(wrapper.emitted('update:modelValue')[0][0]).toEqual(3.5);
|
||||
expect(wrapper.emitted('change')![0]).toEqual([3.5]);
|
||||
expect(wrapper.emitted('update:modelValue')![0]).toEqual([3.5]);
|
||||
});
|
||||
|
||||
test('should not emit change or update:modelValue event when rate is disabled', () => {
|
||||
Reference in New Issue
Block a user