feature/test
Pan 2018-07-13 18:43:50 +08:00
parent d476d960e2
commit 0a73bd3722
5 changed files with 37 additions and 23 deletions

View File

@ -10,7 +10,8 @@
"build": "node build/build.js",
"build:report": "npm_config_report=true node build/build.js",
"lint": "eslint --ext .js,.vue src",
"test": "jest"
"test": "jest",
"test:watch": " jest --watch"
},
"dependencies": {
"axios": "0.17.1",

View File

@ -4,24 +4,21 @@ 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.vm.$on('toggleClick', mockFn)
wrapper.find('.hamburger').trigger('click')
expect(mockFn).toBeCalled()
})
// it('渲染正确', () => {
// expect(wrapper.html()).toContain('<span class="count">0</span>')
// })
it('prop isActive', () => {
const wrapper = shallowMount(Hamburger)
// it('是一个按钮', () => {
// expect(wrapper.contains('button')).toBe(true)
// })
wrapper.setProps({ isActive: true })
expect(wrapper.contains('.is-active')).toBe(true)
// it('snapshot test', () => {
// expect(wrapper.element).toMatchSnapshot()
// })
wrapper.setProps({ isActive: false })
expect(wrapper.contains('.is-active')).toBe(false)
})
})

View File

@ -1,4 +0,0 @@
function sum(a = 1, b = 1) {
return a + b
}
module.exports = sum

View File

@ -1,6 +0,0 @@
import sum from './sum'
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3)
})

View File

@ -0,0 +1,26 @@
import { parseTime } from '@/utils/index.js'
describe('Utils:parseTime', () => {
const d = 1531475641067 // "2018-07-13 17:54:01"
it('timestamp', () => {
expect(parseTime(d)).toBe('2018-07-13 17:54:01')
})
it('ten digits timestamp', () => {
expect(parseTime((d / 1000).toFixed(0))).toBe('2018-07-13 17:54:01')
})
it('new Date', () => {
expect(parseTime(new Date(d))).toBe('2018-07-13 17:54:01')
})
it('format', () => {
expect(parseTime(d, '{y}-{m}-{d} {h}:{i}')).toBe('2018-07-13 17:54')
expect(parseTime(d, '{y}-{m}-{d}')).toBe('2018-07-13')
expect(parseTime(d, '{y}/{m}/{d} {h}-{i}')).toBe('2018/07/13 17-54')
})
it('get the day of the week', () => {
expect(parseTime(d, '{a}')).toBe('五') // 星期五
})
})