test: fix index.spec.ts typing (#8201)

This commit is contained in:
neverland
2021-02-23 19:43:29 +08:00
committed by GitHub
parent f0f89f1c4c
commit 1170262d72
12 changed files with 34 additions and 45 deletions
+6 -5
View File
@@ -1,4 +1,5 @@
import ContactEdit from '..';
import { VueWrapper } from '@vue/test-utils';
import ContactEdit, { ContactInfo } from '..';
import { mount, later } from '../../../test';
const contactInfo = {
@@ -6,7 +7,7 @@ const contactInfo = {
tel: '13000000000',
};
async function submitForm(wrapper) {
async function submitForm(wrapper: VueWrapper<any>) {
const form = wrapper.find('form');
await form.trigger('submit');
return later();
@@ -48,14 +49,14 @@ test('should emit save event after submitting form', async () => {
});
await submitForm(wrapper);
expect(wrapper.emitted('save')[0][0]).toEqual(contactInfo);
expect(wrapper.emitted<[ContactInfo]>('save')[0][0]).toEqual(contactInfo);
});
test('should watch contact info', async () => {
const wrapper = mount(ContactEdit);
await wrapper.setProps({ contactInfo });
await submitForm(wrapper);
expect(wrapper.emitted('save')[0][0]).toEqual(contactInfo);
expect(wrapper.emitted<[ContactInfo]>('save')[0][0]).toEqual(contactInfo);
});
test('should allow deleting contact', async () => {
@@ -69,7 +70,7 @@ test('should allow deleting contact', async () => {
deleteButton.trigger('click');
await later();
document.querySelector('.van-dialog__confirm').click();
document.querySelector<HTMLElement>('.van-dialog__confirm')?.click();
await later();
expect(wrapper.emitted('delete')).toBeTruthy();