update
parent
1ab649b982
commit
23d2043d39
|
@ -1,17 +0,0 @@
|
||||||
<template>
|
|
||||||
<div>
|
|
||||||
<h1>Count: {{ counter }}</h1>
|
|
||||||
|
|
||||||
<button @click="counter++" jest="increment-button">+1</button>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
counter: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
|
@ -35,7 +35,11 @@ export function parseTime(time, cFormat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatTime(time, option) {
|
export function formatTime(time, option) {
|
||||||
time = +time * 1000
|
if (('' + time).length === 10) {
|
||||||
|
time = parseInt(time) * 1000
|
||||||
|
} else {
|
||||||
|
time = +time
|
||||||
|
}
|
||||||
const d = new Date(time)
|
const d = new Date(time)
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
|
|
||||||
|
|
|
@ -1,24 +1,103 @@
|
||||||
// import { shallowMount } from '@vue/test-utils'
|
import { mount, createLocalVue } from '@vue/test-utils'
|
||||||
// import Breadcrumb from '@/components/Breadcrumb.vue'
|
import VueRouter from 'vue-router'
|
||||||
|
import ElementUI from 'element-ui'
|
||||||
|
import Breadcrumb from '@/components/Breadcrumb/index.vue'
|
||||||
|
|
||||||
// describe('Breadcrumb.vue', () => {
|
const localVue = createLocalVue()
|
||||||
// const wrapper = shallowMount(Breadcrumb)
|
localVue.use(VueRouter)
|
||||||
|
localVue.use(ElementUI)
|
||||||
|
|
||||||
// it('toggle', () => {
|
const routes = [
|
||||||
// expect(wrapper.vm.counter).toBe(0)
|
{
|
||||||
// wrapper.find('[jest="increment-button"]').trigger('click')
|
path: '/',
|
||||||
// expect(wrapper.vm.counter).toBe(1)
|
name: 'home',
|
||||||
// })
|
children: [{
|
||||||
|
path: 'dashboard',
|
||||||
|
name: 'dashboard'
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/menu',
|
||||||
|
name: 'menu',
|
||||||
|
children: [{
|
||||||
|
path: 'menu1',
|
||||||
|
name: 'menu1',
|
||||||
|
meta: { title: 'menu1' },
|
||||||
|
children: [{
|
||||||
|
path: 'menu1-1',
|
||||||
|
name: 'menu1-1',
|
||||||
|
meta: { title: 'menu1-1' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'menu1-2',
|
||||||
|
name: 'menu1-2',
|
||||||
|
redirect: 'noredirect',
|
||||||
|
meta: { title: 'menu1-2' },
|
||||||
|
children: [{
|
||||||
|
path: 'menu1-2-1',
|
||||||
|
name: 'menu1-2-1',
|
||||||
|
meta: { title: 'menu1-2-1' }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'menu1-2-2',
|
||||||
|
name: 'menu1-2-2'
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
|
||||||
// // it('渲染正确', () => {
|
const router = new VueRouter({
|
||||||
// // expect(wrapper.html()).toContain('<span class="count">0</span>')
|
routes
|
||||||
// // })
|
})
|
||||||
|
|
||||||
// it('是一个按钮', () => {
|
describe('Breadcrumb.vue', () => {
|
||||||
// expect(wrapper.contains('button')).toBe(true)
|
const wrapper = mount(Breadcrumb, {
|
||||||
// })
|
localVue,
|
||||||
|
router
|
||||||
|
})
|
||||||
|
|
||||||
// // it('snapshot test', () => {
|
it('dashboard', () => {
|
||||||
// // expect(wrapper.element).toMatchSnapshot()
|
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)
|
||||||
|
})
|
||||||
|
it('nested route', () => {
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('click link', () => {
|
||||||
|
router.push('/menu/menu1/menu1-2/menu1-2-2')
|
||||||
|
const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
|
||||||
|
const second = breadcrumbArray.at(1)
|
||||||
|
const href = second.find('a').attributes().href
|
||||||
|
expect(href).toBe('#/menu/menu1')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('noredirect', () => {
|
||||||
|
router.push('/menu/menu1/menu1-2/menu1-2-1')
|
||||||
|
const breadcrumbArray = wrapper.findAll('.el-breadcrumb__inner')
|
||||||
|
const redirectBreadcrumb = breadcrumbArray.at(2)
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import { shallowMount } from '@vue/test-utils'
|
|
||||||
import Counter from '@/components/Counter.vue'
|
|
||||||
|
|
||||||
describe('test Counter.vue', () => {
|
|
||||||
const wrapper = shallowMount(Counter)
|
|
||||||
|
|
||||||
it('increments counter', () => {
|
|
||||||
expect(wrapper.vm.counter).toBe(0)
|
|
||||||
wrapper.find('[jest="increment-button"]').trigger('click')
|
|
||||||
expect(wrapper.vm.counter).toBe(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
// it('渲染正确', () => {
|
|
||||||
// expect(wrapper.html()).toContain('<span class="count">0</span>')
|
|
||||||
// })
|
|
||||||
|
|
||||||
it('是一个按钮', () => {
|
|
||||||
expect(wrapper.contains('button')).toBe(true)
|
|
||||||
})
|
|
||||||
|
|
||||||
// it('snapshot test', () => {
|
|
||||||
// expect(wrapper.element).toMatchSnapshot()
|
|
||||||
// })
|
|
||||||
})
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { formatTime } from '@/utils/index.js'
|
||||||
|
|
||||||
|
describe('Utils:formatTime', () => {
|
||||||
|
const d = 1531475641067 // "2018-07-13 17:54:01"
|
||||||
|
|
||||||
|
it('test now', () => {
|
||||||
|
expect(formatTime(+new Date() - 1)).toBe('刚刚')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('less two minute', () => {
|
||||||
|
expect(formatTime(+new Date() - 60 * 2 * 1000)).toBe('2分钟前')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('less two hour', () => {
|
||||||
|
expect(formatTime(+new Date() - 60 * 60 * 2 * 1000)).toBe('2小时前')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('less one day', () => {
|
||||||
|
expect(formatTime(+new Date() - 60 * 60 * 24 * 1 * 1000)).toBe('1天前')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('more than one day', () => {
|
||||||
|
expect(formatTime(d)).toBe('7月13日17时54分')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('format', () => {
|
||||||
|
expect(formatTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
|
||||||
|
expect(formatTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
|
||||||
|
expect(formatTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue