test: update legacy test cases

This commit is contained in:
chenjiahan 2020-12-31 16:06:49 +08:00
parent 559710f945
commit b03341792e
15 changed files with 88 additions and 88 deletions

View File

@ -75,7 +75,7 @@ test('valid area placeholder confirm', async () => {
test('show area component', async () => {
const { wrapper } = createComponent();
const field = wrapper.findAll('.van-field').at(2);
const field = wrapper.findAll('.van-field')[2];
field.trigger('click');
await later(50);
@ -119,7 +119,7 @@ test('valid name', () => {
data.name = '';
button.trigger('click');
expect(errorInfo.name).toBeTruthy();
field.at(0).trigger('focus');
field[0].trigger('focus');
expect(errorInfo.name).toBeFalsy();
});
@ -128,7 +128,7 @@ test('valid tel', () => {
data.tel = '';
button.trigger('click');
expect(errorInfo.tel).toBeTruthy();
field.at(1).trigger('focus');
field[1].trigger('focus');
expect(errorInfo.tel).toBeFalsy();
});
@ -150,7 +150,7 @@ test('valid addressDetail', () => {
data.addressDetail = '';
button.trigger('click');
expect(errorInfo.addressDetail).toBeTruthy();
field.at(3).trigger('focus');
field[3].trigger('focus');
expect(errorInfo.addressDetail).toBeFalsy();
});
@ -161,7 +161,7 @@ test('valid postal code', () => {
data.postalCode = '123';
button.trigger('click');
expect(errorInfo.postalCode).toBeTruthy();
field.at(4).trigger('focus');
field[4].trigger('focus');
expect(errorInfo.postalCode).toBeFalsy();
// valid result
@ -177,7 +177,7 @@ test('valid postal code', () => {
test('on change detail', () => {
const wrapper = mount(AddressEdit);
const field = wrapper.findAll('.van-field__control').at(3);
const field = wrapper.findAll('.van-field__control')[3];
field.element.value = '123';
field.trigger('input');
@ -245,16 +245,16 @@ test('show search result', async () => {
},
});
const field = wrapper.findAll('.van-field__control').at(3);
const field = wrapper.findAll('.van-field__control')[3];
const input = field.element;
field.trigger('focus');
const items = wrapper.findAll('.van-icon-location-o');
items.at(0).element.parentNode.click();
items[0].element.parentNode.click();
expect(input.value).toEqual('address1 name1');
items.at(1).element.parentNode.click();
items[1].element.parentNode.click();
expect(input.value).toEqual('name2');
items.at(2).element.parentNode.click();
items[2].element.parentNode.click();
expect(input.value).toEqual('address2');
field.trigger('blur');
@ -270,7 +270,7 @@ test('delete address', async () => {
},
});
const deleteButton = wrapper.findAll('.van-button').at(1);
const deleteButton = wrapper.findAll('.van-button')[1];
deleteButton.trigger('click');
await later();
@ -302,7 +302,7 @@ test('click-area event', () => {
},
});
const field = wrapper.findAll('.van-field').at(2);
const field = wrapper.findAll('.van-field')[2];
field.trigger('click');
expect(wrapper.emitted('click-area')[0]).toBeTruthy();
});

View File

@ -69,12 +69,12 @@ test('change option', () => {
const columns = wrapper.findAll('.van-picker-column');
expect(wrapper.html()).toMatchSnapshot();
triggerDrag(columns.at(0), 0, -100);
columns.at(0).find('ul').trigger('transitionend');
triggerDrag(columns[0], 0, -100);
columns[0].find('ul').trigger('transitionend');
expect(wrapper.html()).toMatchSnapshot();
triggerDrag(columns.at(2), 0, -100);
columns.at(2).find('ul').trigger('transitionend');
triggerDrag(columns[2], 0, -100);
columns[2].find('ul').trigger('transitionend');
expect(wrapper.html()).toMatchSnapshot();
expect(onChange.mock.calls[0][1]).toEqual(secondOption);

View File

@ -119,7 +119,7 @@ test('should not trigger select event when click disabled day', async () => {
await later();
wrapper.findAll('.van-calendar__day').at(1).trigger('click');
wrapper.findAll('.van-calendar__day')[1].trigger('click');
expect(formatDate(wrapper.emitted('select'))).toBeFalsy();
});

View File

@ -28,15 +28,15 @@ test('basic mode', async () => {
const wrapper = mount(component);
const titles = wrapper.findAll('.van-collapse-item__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.vm.active).toEqual(['first']);
await later();
titles.at(1).trigger('click');
titles[1].trigger('click');
expect(wrapper.vm.active).toEqual(['first', 1]);
await later();
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.vm.active).toEqual([1]);
wrapper.destroy();
@ -50,17 +50,17 @@ test('accordion', async () => {
});
const titles = wrapper.findAll('.van-collapse-item__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.vm.active).toEqual('first');
titles.at(1).trigger('click');
titles[1].trigger('click');
expect(wrapper.vm.active).toEqual(1);
await later();
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.vm.active).toEqual('first');
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.vm.active).toEqual('');
});
@ -118,7 +118,7 @@ test('lazy render collapse content', async () => {
const titles = wrapper.findAll('.van-collapse-item__title');
titles.at(1).trigger('click');
titles[1].trigger('click');
wrapper.vm.content = 'content';
expect(wrapper.html()).toMatchSnapshot();
});

View File

@ -111,7 +111,7 @@ test('render empty coupon list', () => {
disabledCoupons: [],
},
});
wrapper.findAll('.van-tab').at(1).trigger('click');
wrapper.findAll('.van-tab')[1].trigger('click');
expect(wrapper.html()).toMatchSnapshot();
});

View File

@ -89,7 +89,7 @@ test('year-month type', () => {
expect(wrapper.emitted('confirm')[1][0].getFullYear()).toEqual(2025);
expect(wrapper.emitted('confirm')[1][0].getMonth()).toEqual(0);
triggerDrag(wrapper.findAll('.van-picker-column').at(1), 0, -100);
triggerDrag(wrapper.findAll('.van-picker-column')[1], 0, -100);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[2][0].getFullYear()).toEqual(2025);
expect(wrapper.emitted('confirm')[2][0].getMonth()).toEqual(10);
@ -116,7 +116,7 @@ test('month-day type', () => {
expect(wrapper.emitted('confirm')[1][0].getMonth()).toEqual(11);
expect(wrapper.emitted('confirm')[1][0].getDate()).toEqual(1);
triggerDrag(wrapper.findAll('.van-picker-column').at(1), 0, -300);
triggerDrag(wrapper.findAll('.van-picker-column')[1], 0, -300);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[2][0].getMonth()).toEqual(11);
expect(wrapper.emitted('confirm')[2][0].getDate()).toEqual(31);
@ -134,7 +134,7 @@ test('datehour type', async () => {
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0].getHours()).toEqual(0);
triggerDrag(wrapper.findAll('.van-picker-column').at(3), 0, -300);
triggerDrag(wrapper.findAll('.van-picker-column')[3], 0, -300);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[1][0].getHours()).toEqual(23);
});

View File

@ -30,13 +30,13 @@ test('show dropdown item', async () => {
const titles = wrapper.findAll('.van-dropdown-menu__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.html()).toMatchSnapshot();
titles.at(1).trigger('click');
titles[1].trigger('click');
expect(wrapper.html()).toMatchSnapshot();
titles.at(1).trigger('click');
titles[1].trigger('click');
expect(wrapper.html()).toMatchSnapshot();
});
@ -49,7 +49,7 @@ test('render option icon', async () => {
const titles = wrapper.findAll('.van-dropdown-menu__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.html()).toMatchSnapshot();
});
@ -62,7 +62,7 @@ test('close-on-click-outside', async () => {
const titles = wrapper.findAll('.van-dropdown-menu__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
document.body.click();
expect(wrapper.html()).toMatchSnapshot();
});
@ -76,7 +76,7 @@ test('disable close-on-click-outside', async () => {
const titles = wrapper.findAll('.van-dropdown-menu__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
document.body.click();
expect(wrapper.html()).toMatchSnapshot();
});
@ -93,7 +93,7 @@ test('direction up', async () => {
expect(wrapper.html()).toMatchSnapshot();
const titles = wrapper.findAll('.van-dropdown-menu__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
expect(wrapper.html()).toMatchSnapshot();
window.innerHeight = innerHeight;
@ -105,10 +105,10 @@ test('click option', async () => {
await later();
const titles = wrapper.findAll('.van-dropdown-menu__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
const options = wrapper.findAll('.van-dropdown-item .van-cell');
options.at(1).trigger('click');
options[1].trigger('click');
await later();
expect(wrapper.html()).toMatchSnapshot();
@ -201,14 +201,14 @@ test('change event', async () => {
await later();
const titles = wrapper.findAll('.van-dropdown-menu__title');
titles.at(0).trigger('click');
titles[0].trigger('click');
const options = wrapper.findAll('.van-dropdown-item .van-cell');
options.at(0).trigger('click');
options[0].trigger('click');
expect(onChange).toHaveBeenCalledTimes(0);
options.at(1).trigger('click');
options[1].trigger('click');
expect(onChange).toHaveBeenCalledWith(1);
expect(onChange).toHaveBeenCalledTimes(1);
});

View File

@ -348,14 +348,14 @@ test('validate-trigger - custom trigger in rules', async () => {
const inputs = wrapper.findAll('input');
inputs.at(0).trigger('blur');
inputs[0].trigger('blur');
wrapper.setData({ valueB: '1' });
await later();
wrapper.setData({ valueB: '' });
await later();
expect(wrapper.contains('.van-field__error-message')).toBeFalsy();
inputs.at(1).trigger('blur');
inputs[1].trigger('blur');
wrapper.setData({ valueA: '1' });
await later();
wrapper.setData({ valueA: '' });

View File

@ -29,7 +29,7 @@ test('should scroll to anchor and emit select event after clicking the index-bar
const fn = mockScrollIntoView();
const indexes = wrapper.findAll('.van-index-bar__index');
indexes.at(0).trigger('click');
indexes[0].trigger('click');
expect(fn).toHaveBeenCalledTimes(1);
expect(onSelect).toHaveBeenCalledWith('A');

View File

@ -145,8 +145,8 @@ test('check the direction props', () => {
});
let children = wrapper.findAll('.van-list > div');
expect(children.at(0).is('.van-list__placeholder')).toBeTruthy();
expect(children.at(1).is('.list-item')).toBeTruthy();
expect(children[0].is('.van-list__placeholder')).toBeTruthy();
expect(children[1].is('.list-item')).toBeTruthy();
// change the direction's value
wrapper.setProps({
@ -154,6 +154,6 @@ test('check the direction props', () => {
});
children = wrapper.findAll('.van-list > div');
expect(children.at(0).is('.list-item')).toBeTruthy();
expect(children.at(1).is('.van-list__placeholder')).toBeTruthy();
expect(children[0].is('.list-item')).toBeTruthy();
expect(children[1].is('.van-list__placeholder')).toBeTruthy();
});

View File

@ -14,7 +14,7 @@ test('click number key', () => {
},
});
clickKey(wrapper.findAll('.van-key').at(0));
clickKey(wrapper.findAll('.van-key')[0]);
expect(wrapper.emitted('input')[0][0]).toEqual(1);
wrapper.destroy();
@ -173,8 +173,8 @@ test('bind value', () => {
});
const keys = wrapper.findAll('.van-key');
clickKey(keys.at(0));
clickKey(keys.at(1));
clickKey(keys[0]);
clickKey(keys[1]);
expect(wrapper.vm.value).toEqual('12');
@ -198,8 +198,8 @@ test('maxlength', () => {
});
const keys = wrapper.findAll('.van-key');
clickKey(keys.at(0));
clickKey(keys.at(1));
clickKey(keys[0]);
clickKey(keys[1]);
expect(wrapper.vm.value).toEqual('1');
expect(onInput).toHaveBeenCalledTimes(1);

View File

@ -230,7 +230,7 @@ test('click column item', () => {
},
});
wrapper.findAll('.van-picker-column__item').at(3).trigger('click');
wrapper.findAll('.van-picker-column__item')[3].trigger('click');
expect(wrapper.emitted('change')[0][1]).toEqual(columns[1]);
});
@ -332,7 +332,7 @@ test('readonly prop', () => {
triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
wrapper.find('.van-picker-column ul').trigger('transitionend');
wrapper.findAll('.van-picker-column__item').at(3).trigger('click');
wrapper.findAll('.van-picker-column__item')[3].trigger('click');
expect(wrapper.emitted('change')).toBeFalsy();
});

View File

@ -25,16 +25,16 @@ test('radio-group change', () => {
const icons = wrapper.findAll('.van-radio__icon');
const labels = wrapper.findAll('.van-radio__label');
icons.at(2).trigger('click');
icons[2].trigger('click');
expect(wrapper.vm.result).toEqual('c');
expect(wrapper.emitted('change')[0][0]).toEqual('c');
labels.at(1).trigger('click');
labels[1].trigger('click');
expect(wrapper.vm.result).toEqual('b');
expect(wrapper.emitted('change')[1][0]).toEqual('b');
icons.at(3).trigger('click');
labels.at(3).trigger('click');
icons[3].trigger('click');
labels[3].trigger('click');
expect(wrapper.vm.result).toEqual('b');
});
@ -60,7 +60,7 @@ test('radio group disabled', () => {
});
const icons = wrapper.findAll('.van-radio__icon');
icons.at(2).trigger('click');
icons[2].trigger('click');
expect(wrapper.emitted('change')).toBeFalsy();
});

View File

@ -50,8 +50,8 @@ test('click to switch tab', async () => {
expect(wrapper.html()).toMatchSnapshot();
const tabs = wrapper.findAll('.van-tab');
tabs.at(1).trigger('click');
tabs.at(2).trigger('click');
tabs[1].trigger('click');
tabs[2].trigger('click');
await later();
expect(wrapper.html()).toMatchSnapshot();
expect(onChange).toHaveBeenCalledTimes(1);
@ -165,10 +165,10 @@ test('click event', async () => {
const tabs = wrapper.findAll('.van-tab');
tabs.at(0).trigger('click');
tabs[0].trigger('click');
expect(onClick).toHaveBeenCalledWith(0, 'title1');
tabs.at(1).trigger('click');
tabs[1].trigger('click');
expect(onDisabled).toHaveBeenCalledWith(1, 'title2');
});
@ -201,13 +201,13 @@ test('name prop', async () => {
expect(wrapper.html()).toMatchSnapshot();
const tabs = wrapper.findAll('.van-tab');
tabs.at(1).trigger('click');
tabs[1].trigger('click');
expect(onClick).toHaveBeenCalledWith('b', 'title2');
expect(onChange).toHaveBeenCalledWith('b', 'title2');
expect(onChange).toHaveBeenCalledTimes(1);
tabs.at(2).trigger('click');
tabs[2].trigger('click');
expect(onDisabled).toHaveBeenCalledWith('c', 'title3');
expect(onChange).toHaveBeenCalledTimes(1);
});
@ -228,7 +228,7 @@ test('set name to zero', async () => {
});
const tabs = wrapper.findAll('.van-tab');
tabs.at(1).trigger('click');
tabs[1].trigger('click');
expect(onClick).toHaveBeenCalledWith(0, 'title2');
});
@ -289,7 +289,7 @@ test('scrollspy prop', async () => {
expect(wrapper.html()).toMatchSnapshot();
const tabs = wrapper.findAll('.van-tab');
tabs.at(2).trigger('click');
tabs[2].trigger('click');
expect(onChange).toHaveBeenCalledWith('c', 'title3');
await later();
@ -347,8 +347,8 @@ test('rendered event', async () => {
expect(wrapper.find('.van-tab__pane')).toMatchSnapshot();
const tabs = wrapper.findAll('.van-tab');
tabs.at(1).trigger('click');
tabs.at(0).trigger('click');
tabs[1].trigger('click');
tabs[0].trigger('click');
await later();
expect(onRendered).toHaveBeenCalledTimes(2);
@ -405,17 +405,17 @@ test('before-change prop', async () => {
await later();
const tabs = wrapper.findAll('.van-tab');
tabs.at(1).trigger('click');
tabs[1].trigger('click');
expect(onChange).toHaveBeenCalledTimes(0);
tabs.at(2).trigger('click');
tabs[2].trigger('click');
expect(onChange).toHaveBeenCalledTimes(1);
expect(onChange).toHaveBeenLastCalledWith(2, 'title3');
tabs.at(3).trigger('click');
tabs[3].trigger('click');
expect(onChange).toHaveBeenCalledTimes(1);
tabs.at(4).trigger('click');
tabs[4].trigger('click');
await later();
expect(onChange).toHaveBeenCalledTimes(2);
expect(onChange).toHaveBeenLastCalledWith(4, 'title5');

View File

@ -41,7 +41,7 @@ test('click-nav event', () => {
});
const navItems = wrapper.findAll('.van-tree-select__nav-item');
navItems.at(1).trigger('click');
navItems[1].trigger('click');
expect(onClickNav).toHaveBeenCalledWith(1);
});
@ -61,7 +61,7 @@ test('click-item event', () => {
});
const items = wrapper.findAll('.van-tree-select__item');
items.at(0).trigger('click');
items[0].trigger('click');
expect(onClickItem).toHaveBeenCalledWith(mockItem);
});
@ -86,7 +86,7 @@ test('click disabled nav', () => {
});
const items = wrapper.findAll('.van-tree-select__nav-item');
items.at(0).trigger('click');
items[0].trigger('click');
expect(onClickNav).toHaveBeenCalledTimes(0);
});
@ -114,7 +114,7 @@ test('click disabled item', () => {
});
const items = wrapper.findAll('.van-tree-select__item');
items.at(0).trigger('click');
items[0].trigger('click');
expect(onClickItem).toHaveBeenCalledTimes(0);
});
@ -177,7 +177,7 @@ test('use sync modifier in main-active-index', () => {
});
const navItems = wrapper.findAll('.van-tree-select__nav-item');
navItems.at(0).trigger('click');
navItems[0].trigger('click');
expect(wrapper.vm.mainActiveIndex).toEqual(0);
});
@ -206,7 +206,7 @@ test('use sync modifier in active-id', () => {
});
const items = wrapper.findAll('.van-tree-select__item');
items.at(1).trigger('click');
items[1].trigger('click');
expect(wrapper.vm.activeId).toEqual(mockItem2.id);
});
@ -235,12 +235,12 @@ test('multiple select', () => {
});
const items = wrapper.findAll('.van-tree-select__item');
items.at(0).trigger('click');
items.at(1).trigger('click');
items[0].trigger('click');
items[1].trigger('click');
expect(wrapper.vm.activeId).toEqual([mockItem.id, mockItem2.id]);
items.at(0).trigger('click');
items.at(1).trigger('click');
items[0].trigger('click');
items[1].trigger('click');
expect(wrapper.vm.activeId).toEqual([]);
});
@ -268,8 +268,8 @@ test('max prop', () => {
});
const items = wrapper.findAll('.van-tree-select__item');
items.at(0).trigger('click');
items.at(1).trigger('click');
items[0].trigger('click');
items[1].trigger('click');
expect(wrapper.vm.activeId).toEqual([mockItem.id]);
});
@ -288,7 +288,7 @@ test('className of nav', () => {
});
const items = wrapper.findAll('.van-tree-select__nav-item');
expect(items.at(0).element.classList.contains('my-class')).toBeTruthy();
expect(items[0].element.classList.contains('my-class')).toBeTruthy();
});
test('should sync value before trigger click-item event', (done) => {
@ -322,7 +322,7 @@ test('should sync value before trigger click-item event', (done) => {
});
const items = wrapper.findAll('.van-tree-select__item');
items.at(1).trigger('click');
items[1].trigger('click');
});
test('selected-icon prop', () => {