Skip to content

Commit

Permalink
fix: tabs test script
Browse files Browse the repository at this point in the history
  • Loading branch information
Lydanne committed Oct 6, 2020
1 parent 5bbf84f commit 8301b24
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/tab-pane/TabPane.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
})
if (!elTabs) {
console.error('Element: not find ETabs')
console.error('Element: not find parent ETabs')
return
}
index.value = elTabs.ctx.tabList.length
Expand Down
79 changes: 79 additions & 0 deletions packages/tabs/__tests__/Tabs.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { mount } from '@vue/test-utils'
import { h, nextTick } from '@vue/runtime-core'
import Tabs from '../Tabs'
import TabPane from '../../tab-pane/TabPane'

describe('Tabs', () => {
it('Tabs and TabPane simple to use', async () => {
const wrapper = mount(Tabs, {
slots: {
default: {
render() {
return [
h(TabPane, { label: '标签1' }, () => '内容1'),
h(TabPane, { label: '标签2' }, () => '内容2')
]
}
}
}
})
await nextTick()
expect(wrapper.vm.tabList.length).toBe(2)
const tab = wrapper.findAll('[role=tab]')
await tab[1].trigger('click')
await nextTick()
expect(tab[1].classes()).toContain('is-active')
expect(wrapper.vm.state.activeIndex === 1).toBeTruthy()
})

it('Tabs and TabPane use vModel', async () => {
const wrapper = mount(Tabs, {
props: {
modelValue: 'b1',
'onUpdate:modelValue': (name) => {
expect(name).toBe('b2')
}
},
slots: {
default: {
render() {
return [
h(TabPane, { label: '标签1', name: 'b1' }, () => '内容1'),
h(TabPane, { label: '标签2', name: 'b2' }, () => '内容2')
]
}
}
}
})
await nextTick()
const tab = wrapper.findAll('[role=tab]')
await tab[1].trigger('click')
await nextTick()
expect(tab[1].classes()).toContain('is-active')
})

it('Tabs and TabPane listen edit event', async () => {
const wrapper = mount(Tabs, {
props: {
editable: true,
onEdit(targetName, action) {
expect(targetName).toBe('b2')
expect(action).toBe('remove')
}
},
slots: {
default: {
render() {
return [
h(TabPane, { label: '标签1', name: 'b1' }, () => '内容1'),
h(TabPane, { label: '标签2', name: 'b2' }, () => '内容2')
]
}
}
}
})
await nextTick()
const tab = wrapper.findAll('[role=tab]')
await tab[1].find('.el-icon-close').trigger('click')
})
})

0 comments on commit 8301b24

Please sign in to comment.