This commit is contained in:
joylink_cuiweidong 2020-12-31 13:47:23 +08:00
commit a3860cc279
3 changed files with 128 additions and 127 deletions

View File

@ -1,11 +1,11 @@
import { mount, createLocalVue } from '@vue/test-utils'
import VueRouter from 'vue-router'
import ElementUI from 'element-ui'
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import { mount, createLocalVue } from '@vue/test-utils';
import VueRouter from 'vue-router';
import ElementUI from 'element-ui';
import Breadcrumb from '@/components/Breadcrumb/index.vue';
const localVue = createLocalVue()
localVue.use(VueRouter)
localVue.use(ElementUI)
const localVue = createLocalVue();
localVue.use(VueRouter);
localVue.use(ElementUI);
const routes = [
{
@ -44,37 +44,37 @@ const routes = [
}]
}]
}]
}]
}];
const router = new VueRouter({
routes
})
});
describe('Breadcrumb.vue', () => {
const wrapper = mount(Breadcrumb, {
localVue,
router
})
});
it('dashboard', () => {
router.push('/dashboard')
const len = wrapper.findAll('.el-breadcrumb__inner').length
expect(len).toBe(1)
})
router.push('/dashboard');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(1);
});
it('normal route', () => {
router.push('/menu/menu1')
const len = wrapper.findAll('.el-breadcrumb__inner').length
expect(len).toBe(2)
})
router.push('/menu/menu1');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(2);
});
it('nested route', () => {
router.push('/menu/menu1/menu1-2/menu1-2-1')
const len = wrapper.findAll('.el-breadcrumb__inner').length
expect(len).toBe(4)
})
router.push('/menu/menu1/menu1-2/menu1-2-1');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(4);
});
it('no meta.title', () => {
router.push('/menu/menu1/menu1-2/menu1-2-2')
const len = wrapper.findAll('.el-breadcrumb__inner').length
expect(len).toBe(3)
})
router.push('/menu/menu1/menu1-2/menu1-2-2');
const len = wrapper.findAll('.el-breadcrumb__inner').length;
expect(len).toBe(3);
});
// it('click link', () => {
// router.push('/menu/menu1/menu1-2/menu1-2-2')
// const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
@ -90,9 +90,9 @@ describe('Breadcrumb.vue', () => {
// expect(redirectBreadcrumb.contains('a')).toBe(false)
// })
it('last breadcrumb', () => {
router.push('/menu/menu1/menu1-2/menu1-2-1')
const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
const redirectBreadcrumb = breadcrumbArray.at(3)
expect(redirectBreadcrumb.contains('a')).toBe(false)
})
})
router.push('/menu/menu1/menu1-2/menu1-2-1');
const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner');
const redirectBreadcrumb = breadcrumbArray.at(3);
expect(redirectBreadcrumb.contains('a')).toBe(false);
});
});

View File

@ -1,18 +1,19 @@
import { shallowMount } from '@vue/test-utils'
import Hamburger from '@/components/Hamburger/index.vue'
import { shallowMount } from '@vue/test-utils';
import Hamburger from '@/components/Hamburger/index.vue';
describe('Hamburger.vue', () => {
it('toggle click', () => {
const wrapper = shallowMount(Hamburger)
const mockFn = jest.fn()
wrapper.vm.$on('toggleClick', mockFn)
wrapper.find('.hamburger').trigger('click')
expect(mockFn).toBeCalled()
})
const wrapper = shallowMount(Hamburger);
const mockFn = jest.fn();
wrapper.vm.$on('toggleClick', mockFn);
wrapper.find('.hamburger').trigger('click');
expect(mockFn).toBeCalled();
});
it('prop isActive', () => {
const wrapper = shallowMount(Hamburger)
wrapper.setProps({ isActive: true })
expect(wrapper.contains('.is-active')).toBe(true)
wrapper.setProps({ isActive: false })
expect(wrapper.contains('.is-active')).toBe(false)
})
})
const wrapper = shallowMount(Hamburger);
wrapper.setProps({ isActive: true });
expect(wrapper.contains('.is-active')).toBe(true);
wrapper.setProps({ isActive: false });
expect(wrapper.contains('.is-active')).toBe(false);
});
});

View File

@ -1,22 +1,22 @@
import { shallowMount } from '@vue/test-utils'
import SvgIcon from '@/components/SvgIcon/index.vue'
import { shallowMount } from '@vue/test-utils';
import SvgIcon from '@/components/SvgIcon/index.vue';
describe('SvgIcon.vue', () => {
it('iconClass', () => {
const wrapper = shallowMount(SvgIcon, {
propsData: {
iconClass: 'test'
}
})
expect(wrapper.find('use').attributes().href).toBe('#icon-test')
})
});
expect(wrapper.find('use').attributes().href).toBe('#icon-test');
});
it('className', () => {
const wrapper = shallowMount(SvgIcon, {
propsData: {
iconClass: 'test'
}
})
expect(wrapper.classes().length).toBe(1)
wrapper.setProps({ className: 'test' })
expect(wrapper.classes().includes('test')).toBe(true)
})
})
});
expect(wrapper.classes().length).toBe(1);
wrapper.setProps({ className: 'test' });
expect(wrapper.classes().includes('test')).toBe(true);
});
});