test: fix some commented out test cases (#9691)

* test: fix some commented out test cases

* fix: remove log
This commit is contained in:
neverland 2021-10-18 17:54:54 +08:00 committed by GitHub
parent 3a904af565
commit 8bb10e4417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 80 deletions

View File

@ -17,6 +17,16 @@ exports[`should render title slot correctly 1`] = `
</h2>
`;
exports[`should select correct option when value changed 1`] = `
<li class="van-cascader__option van-cascader__option--selected">
<span>
Wenzhou
</span>
<i class="van-badge__wrapper van-icon van-icon-success van-cascader__selected-icon">
</i>
</li>
`;
exports[`should update tabs when previous tab is clicked 1`] = `
<div class="van-cascader">
<div class="van-cascader__header">

View File

@ -102,21 +102,20 @@ test('should render option slot correctly', async () => {
expect(wrapper.find('.van-cascader__option').html()).toMatchSnapshot();
});
// TODO
// test('should select correct option when value changed', async () => {
// const wrapper = mount(Cascader, {
// props: {
// options,
// },
// });
test('should select correct option when value changed', async () => {
const wrapper = mount(Cascader, {
props: {
options,
},
});
// await later();
// await wrapper.setProps({ modelValue: '330304' });
// await later();
// const selectedOptions = wrapper.findAll('.van-cascader__option--selected');
// const lastSelectedOption = selectedOptions[selectedOptions.length - 1];
// expect(lastSelectedOption.html()).toMatchSnapshot();
// });
await later();
await wrapper.setProps({ modelValue: '330304' });
await later();
const selectedOptions = wrapper.findAll('.van-cascader__option--selected');
const lastSelectedOption = selectedOptions[selectedOptions.length - 1];
expect(lastSelectedOption.html()).toMatchSnapshot();
});
test('should reset selected options when value is set to empty', async () => {
const wrapper = mount(Cascader, {

View File

@ -1,18 +1,17 @@
import { Circle } from '..';
import { mount, later } from '../../../test';
// TODO
// test('should update to final rate immediately if speed is 0', async () => {
// const wrapper = mount(Circle, {
// props: {
// rate: 50,
// currentRate: 0,
// },
// });
test('should update to final rate immediately if speed is 0', async () => {
const wrapper = mount(Circle, {
props: {
rate: 50,
currentRate: 0,
},
});
// await later();
// expect(wrapper.emitted('update:currentRate')).toBeTruthy();
// });
await later();
expect(wrapper.emitted('update:currentRate')).toBeTruthy();
});
test('should emit "update:currentRate" event during animation', async () => {
const wrapper = mount(Circle, {

View File

@ -44,6 +44,19 @@ exports[`should render label slot correctly 1`] = `
</div>
`;
exports[`should render textarea when type is textarea 1`] = `
<div class="van-cell van-field">
<div class="van-cell__value van-cell__value--alone van-field__value">
<div class="van-field__body">
<textarea class="van-field__control"
style="height: auto;"
>
</textarea>
</div>
</div>
</div>
`;
exports[`should render word limit correctly 1`] = `
<div class="van-cell van-field">
<div class="van-cell__value van-cell__value--alone van-field__value">

View File

@ -1,5 +1,5 @@
import { Field } from '..';
import { mount } from '../../../test';
import { mount, later } from '../../../test';
test('should emit "update:modelValue" event when after inputting', () => {
const wrapper = mount(Field);
@ -95,50 +95,51 @@ test('should format input value when type is digit', () => {
expect(wrapper.emitted('update:modelValue')[2][0]).toEqual('123');
});
// TODO
// test('should render textarea when type is textarea', async () => {
// const wrapper = mount(Field, {
// props: {
// type: 'textarea',
// autosize: true,
// },
// });
test('should render textarea when type is textarea', async () => {
const wrapper = mount(Field, {
props: {
type: 'textarea',
autosize: true,
},
});
// await later();
// expect(wrapper.html()).toMatchSnapshot();
// });
await later();
expect(wrapper.html()).toMatchSnapshot();
});
// test('autosize textarea field', () => {
// const wrapper = mount(Field, {
// props: {
// type: 'textarea',
// autosize: {},
// },
// });
test('should autosize textarea field', async () => {
const wrapper = mount(Field, {
props: {
type: 'textarea',
autosize: {},
},
});
// const value = '1'.repeat(20);
// const textarea = wrapper.find('.van-field__control');
const value = '1'.repeat(20);
const textarea = wrapper.find('.van-field__control');
// wrapper.setProps({ value });
// expect(textarea.element.value).toEqual(value);
// });
await wrapper.setProps({ modelValue: value });
expect(textarea.element.value).toEqual(value);
});
// test('autosize object', async () => {
// const wrapper = mount(Field, {
// props: {
// type: 'textarea',
// autosize: {
// maxHeight: 100,
// minHeight: 50,
// },
// },
// });
test('should allow autosize prop be be an object', async () => {
window.scrollTo = jest.fn();
// const textarea = wrapper.find('.van-field__control');
const wrapper = mount(Field, {
props: {
type: 'textarea',
autosize: {
maxHeight: 100,
minHeight: 50,
},
},
});
// await later();
// expect(textarea.style.height).toEqual('50px');
// });
const textarea = wrapper.find('.van-field__control');
await later();
expect(textarea.style.height).toEqual('50px');
});
test('should call input.focus when vm.focus is called', () => {
const wrapper = mount(Field);
@ -390,24 +391,18 @@ test('should render colon when using colon prop', () => {
expect(wrapper.find('.van-field__label').html()).toMatchSnapshot();
});
// TODO
// test('should blur search input on enter', () => {
// const wrapper = mount(Field);
test('should blur search input after pressing enter', async () => {
const wrapper = mount(Field, {
props: {
type: 'search',
},
});
// wrapper.find('input').element.focus();
// wrapper.find('input').trigger('keypress.enter');
// expect(wrapper.emitted('blur')).toBeFalsy();
// wrapper.setProps({ type: 'textarea' });
// wrapper.find('textarea').element.focus();
// wrapper.find('textarea').trigger('keypress.enter');
// expect(wrapper.emitted('blur')).toBeFalsy();
// wrapper.setProps({ type: 'search' });
// wrapper.find('input').element.focus();
// wrapper.find('input').trigger('keypress.enter');
// expect(wrapper.emitted('blur')).toBeTruthy();
// });
const onBlur = jest.fn();
wrapper.find('input').element.blur = onBlur;
await wrapper.find('input').trigger('keypress.enter');
expect(onBlur).toHaveBeenCalledTimes(1);
});
test('should format value after mounted if initial modelValue is null', () => {
const wrapper = mount(Field, {