All files / src/components/u-list-view.vue/fixes pageNumber.test.js

0% Statements 0/23
100% Branches 0/0
0% Functions 0/4
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                                                   
import { mount } from '@vue/test-utils';
 
import PageNumberDemo from './__demos__/pageNumber.vue';
 
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
 
describe('u-list-view.vue', () => {
    it('pageNumber 变化', async () => {
        const wrapper = mount(PageNumberDemo);
        await sleep(16);
 
        // 点击到第二页
        wrapper.vm.$refs.listview.$refs.pagination.select(2);
        await sleep(16);
        const selectedPage = wrapper.find('a[selected="selected"]');
        expect(selectedPage.text()).toBe('2');
        expect(wrapper).toMatchSnapshot();
 
        // 数据源变化时还原到第一页
        const button = wrapper.find('#changelistbutton');
        await button.trigger('click');
        await sleep(16);
        const selectedPage1 = wrapper.find('a[selected="selected"]');
        expect(selectedPage1.text()).toBe('1');
        expect(wrapper).toMatchSnapshot();
 
        // 改变pageNumber
        wrapper.vm.pageNumber = 3;
        await sleep(16);
        const selectedPage2 = wrapper.find('a[selected="selected"]');
        expect(selectedPage2.text()).toBe('3');
        expect(wrapper).toMatchSnapshot();
    });
});