test: add typing for some test cases (#8243)

This commit is contained in:
neverland
2021-03-02 09:33:08 +08:00
committed by GitHub
parent 569d353b4a
commit bbb882acfa
13 changed files with 50 additions and 44 deletions
@@ -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', () => {