123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780 |
- import { defineComponent, nextTick, ref } from 'vue'
- import { mount } from '@vue/test-utils'
- import { describe, expect, test, vi } from 'vitest'
- import { EVENT_CODE } from '@element-plus/constants'
- import Tabs from '../src/tabs'
- import TabPane from '../src/tab-pane.vue'
- import TabNav from '../src/tab-nav'
- import type { TabPaneName } from '../src/tabs'
- import type { TabsPaneContext } from '@element-plus/components/tabs'
- const Comp = defineComponent({
- components: {
- TabPane,
- },
- setup() {
- return () => (
- <TabPane name="tab1" label="tab1">
- Tab 1 content
- </TabPane>
- )
- },
- })
- describe('Tabs.vue', () => {
- test('create', async () => {
- const wrapper = mount(() => (
- <Tabs>
- <TabPane label="label-1">A</TabPane>
- <TabPane label="label-2">B</TabPane>
- <TabPane label="label-3" ref="pane-click">
- C
- </TabPane>
- <TabPane label="label-4">D</TabPane>
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- const navWrapper = wrapper.findComponent(TabNav)
- const panesWrapper = wrapper.findAllComponents(TabPane)
- await nextTick()
- const navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper[0].classes('is-active')).toBe(true)
- expect(panesWrapper[0].classes('el-tab-pane')).toBe(true)
- expect(panesWrapper[0].attributes('id')).toBe('pane-0')
- expect(panesWrapper[0].attributes('aria-hidden')).toEqual('false')
- expect(tabsWrapper.vm.$.exposed!.currentName.value).toEqual('0')
- await navItemsWrapper[2].trigger('click')
- expect(navItemsWrapper[0].classes('is-active')).toBe(false)
- expect(panesWrapper[0].attributes('aria-hidden')).toEqual('true')
- expect(navItemsWrapper[2].classes('is-active')).toBe(true)
- expect(panesWrapper[2].attributes('aria-hidden')).toEqual('false')
- expect(tabsWrapper.vm.$.exposed!.currentName.value).toEqual('2')
- })
- test('active-name', async () => {
- const activeName = ref<TabPaneName | undefined>('b')
- const handleClick = (tab: TabsPaneContext) => {
- activeName.value = tab.paneName
- }
- const wrapper = mount(() => (
- <Tabs v-model={activeName.value} onTabClick={handleClick}>
- <TabPane name="a" label="label-1">
- A
- </TabPane>
- <TabPane name="b" label="label-2">
- B
- </TabPane>
- <TabPane name="c" label="label-3" ref="pane-click">
- C
- </TabPane>
- <TabPane name="d" label="label-4">
- D
- </TabPane>
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- const navWrapper = wrapper.findComponent(TabNav)
- const panesWrapper = wrapper.findAllComponents(TabPane)
- await nextTick()
- const navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper[1].classes('is-active')).toBe(true)
- expect(panesWrapper[1].classes('el-tab-pane')).toBe(true)
- expect(panesWrapper[1].attributes('id')).toBe('pane-b')
- expect(panesWrapper[1].attributes('aria-hidden')).toEqual('false')
- expect(tabsWrapper.vm.$.exposed!.currentName.value).toEqual('b')
- await navItemsWrapper[2].trigger('click')
- expect(navItemsWrapper[1].classes('is-active')).toBe(false)
- expect(panesWrapper[1].attributes('aria-hidden')).toEqual('true')
- expect(navItemsWrapper[2].classes('is-active')).toBe(true)
- expect(panesWrapper[2].attributes('aria-hidden')).toEqual('false')
- expect(tabsWrapper.vm.$.exposed!.currentName.value).toEqual('c')
- })
- test('card', async () => {
- const wrapper = mount(() => (
- <Tabs type="card">
- <TabPane label="label-1">A</TabPane>
- <TabPane label="label-2">B</TabPane>
- <TabPane label="label-3" ref="pane-click">
- C
- </TabPane>
- <TabPane label="label-4">D</TabPane>
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- expect(tabsWrapper.classes('el-tabs--card')).toBe(true)
- })
- test('border card', async () => {
- const wrapper = mount(() => (
- <Tabs type="border-card">
- <TabPane label="label-1">A</TabPane>
- <TabPane label="label-2">B</TabPane>
- <TabPane label="label-3" ref="pane-click">
- C
- </TabPane>
- <TabPane label="label-4">D</TabPane>
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- expect(tabsWrapper.classes('el-tabs--border-card')).toBe(true)
- })
- test('dynamic', async () => {
- const tabs = ref([
- {
- label: 'tab1',
- name: 'tab1',
- },
- {
- label: 'tab2',
- name: 'tab2',
- },
- {
- label: 'tab3',
- name: 'tab3',
- },
- {
- label: 'tab4',
- name: 'tab4',
- },
- ])
- const wrapper = mount(() => (
- <Tabs type="card" ref="tabs">
- {tabs.value.map((tab) => (
- <TabPane label={tab.label} name={tab.name} key={tab.name}>
- Test Content
- </TabPane>
- ))}
- </Tabs>
- ))
- let navWrapper = wrapper.findComponent(TabNav)
- let panesWrapper = wrapper.findAllComponents(TabPane)
- await nextTick()
- let navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper.length).toEqual(4)
- expect(panesWrapper.length).toEqual(4)
- tabs.value.push({ label: 'tab5', name: 'tab5' })
- await nextTick()
- navWrapper = wrapper.findComponent(TabNav)
- panesWrapper = wrapper.findAllComponents(TabPane)
- navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper.length).toEqual(5)
- expect(panesWrapper.length).toEqual(5)
- })
- test('editable', async () => {
- const editableTabsValue = ref('2')
- const editableTabs = ref([
- {
- title: 'Tab 1',
- name: '1',
- content: 'Tab 1 content',
- },
- {
- title: 'Tab 2',
- name: '2',
- content: 'Tab 2 content',
- },
- {
- title: 'Tab 3',
- name: '3',
- content: 'Tab 3 content',
- },
- ])
- const tabIndex = ref(3)
- const handleTabsEdit = (
- targetName: TabPaneName | undefined,
- action: 'remove' | 'add'
- ) => {
- if (action === 'add') {
- const newTabName = `${++tabIndex.value}`
- editableTabs.value.push({
- title: 'New Tab',
- name: newTabName,
- content: 'New Tab content',
- })
- editableTabsValue.value = newTabName
- }
- if (action === 'remove') {
- const tabs = editableTabs.value
- let activeName = editableTabsValue.value
- if (activeName === targetName) {
- tabs.forEach((tab, index) => {
- if (tab.name === targetName) {
- const nextTab = tabs[index + 1] || tabs[index - 1]
- if (nextTab) {
- activeName = nextTab.name
- }
- }
- })
- }
- editableTabsValue.value = activeName
- editableTabs.value = tabs.filter((tab) => tab.name !== targetName)
- }
- }
- const wrapper = mount(() => (
- <Tabs
- ref="tabs"
- v-model={editableTabsValue.value}
- type="card"
- editable
- onEdit={handleTabsEdit}
- >
- {editableTabs.value.map((tab) => (
- <TabPane key={tab.name} label={tab.title} name={tab.name}>
- {tab.content}
- </TabPane>
- ))}
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- let panesWrapper = wrapper.findAllComponents(TabPane)
- await nextTick()
- let navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper.length).toEqual(3)
- expect(panesWrapper.length).toEqual(3)
- expect(navItemsWrapper[1].classes('is-active')).toBe(true)
- // remove one tab, check panes length
- await navItemsWrapper[1].find('.is-icon-close').trigger('click')
- panesWrapper = wrapper.findAllComponents(TabPane)
- navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper.length).toEqual(2)
- expect(panesWrapper.length).toEqual(2)
- // add one tab, check panes length and current tab
- await wrapper.find('.el-tabs__new-tab').trigger('click')
- panesWrapper = wrapper.findAllComponents(TabPane)
- navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper.length).toEqual(3)
- expect(panesWrapper.length).toEqual(3)
- expect(navItemsWrapper[2].classes('is-active')).toBe(true)
- })
- test('addable & closable', async () => {
- const editableTabsValue = ref('2')
- const editableTabs = ref([
- {
- title: 'Tab 1',
- name: '1',
- content: 'Tab 1 content',
- },
- {
- title: 'Tab 2',
- name: '2',
- content: 'Tab 2 content',
- },
- ])
- const tabIndex = ref(2)
- const addTab = () => {
- const newTabName = `${++tabIndex.value}`
- editableTabs.value.push({
- title: 'New Tab',
- name: newTabName,
- content: 'New Tab content',
- })
- editableTabsValue.value = newTabName
- }
- const removeTab = (targetName: TabPaneName) => {
- const tabs = editableTabs.value
- let activeName = editableTabsValue.value
- if (activeName === targetName) {
- tabs.forEach((tab, index) => {
- if (tab.name === targetName) {
- const nextTab = tabs[index + 1] || tabs[index - 1]
- if (nextTab) {
- activeName = nextTab.name
- }
- }
- })
- }
- editableTabsValue.value = activeName
- editableTabs.value = tabs.filter((tab) => tab.name !== targetName)
- }
- const wrapper = mount(() => (
- <Tabs
- ref="tabs"
- v-model={editableTabsValue.value}
- type="card"
- addable
- closable
- onTabAdd={addTab}
- onTabRemove={removeTab}
- >
- {editableTabs.value.map((item) => (
- <TabPane
- label={item.title}
- key={item.name}
- name={item.name}
- ></TabPane>
- ))}
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- await nextTick()
- await wrapper.find('.el-tabs__new-tab').trigger('click')
- let navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- let panesWrapper = wrapper.findAllComponents(TabPane)
- expect(navItemsWrapper.length).toEqual(3)
- expect(panesWrapper.length).toEqual(3)
- expect(navItemsWrapper[2].classes('is-active')).toBe(true)
- await navItemsWrapper[2].find('.is-icon-close').trigger('click')
- panesWrapper = wrapper.findAllComponents(TabPane)
- navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper.length).toEqual(2)
- expect(panesWrapper.length).toEqual(2)
- })
- test('tab order', async () => {
- const editableTabs = ref([
- {
- title: 'Tab 1',
- name: '1',
- content: 'Tab 1 content',
- },
- {
- title: 'Tab 2',
- name: '2',
- content: 'Tab 2 content',
- },
- ])
- const wrapper = mount(() => (
- <Tabs ref="tabs" type="card">
- {editableTabs.value.map((item) => (
- <TabPane
- label={item.title}
- key={item.name}
- name={item.name}
- ></TabPane>
- ))}
- </Tabs>
- ))
- editableTabs.value.splice(1, 0, {
- title: 'Tab 3',
- name: '3',
- content: 'Tab 3 content',
- })
- await nextTick()
- const items = wrapper.findAll('.el-tabs__item')
- editableTabs.value.forEach((tab, index) => {
- expect(items[index].element.textContent).toEqual(tab.title)
- })
- })
- test('closable in tab-pane', async () => {
- const wrapper = mount(() => (
- <Tabs type="card" ref="tabs">
- <TabPane label="label-1" closable>
- A
- </TabPane>
- <TabPane label="label-2">B</TabPane>
- <TabPane label="label-3" closable>
- C
- </TabPane>
- <TabPane label="label-4">D</TabPane>
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- await nextTick()
- expect(navWrapper.findAll('.is-icon-close').length).toBe(2)
- })
- test('disabled', async () => {
- const wrapper = mount(() => (
- <Tabs type="card" ref="tabs">
- <TabPane label="label-1">A</TabPane>
- <TabPane disabled label="label-2" ref="disabled">
- B
- </TabPane>
- <TabPane label="label-3">C</TabPane>
- <TabPane label="label-4">D</TabPane>
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- await nextTick()
- const navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper[1].classes('is-active')).toBe(false)
- await navItemsWrapper[1].trigger('click')
- expect(navItemsWrapper[1].classes('is-active')).toBe(false)
- })
- test('tab-position', async () => {
- const wrapper = mount(() => (
- <Tabs ref="tabs" tab-position="left">
- <TabPane label="label-1">A</TabPane>
- <TabPane label="label-2">B</TabPane>
- <TabPane label="label-3" ref="pane-click">
- C
- </TabPane>
- <TabPane label="label-4">D</TabPane>
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- await nextTick()
- expect(tabsWrapper.classes('el-tabs--left')).toBe(true)
- expect(tabsWrapper.find('.el-tabs__header').classes('is-left')).toBe(true)
- expect(tabsWrapper.find('.el-tabs__nav-wrap').classes('is-left')).toBe(true)
- expect(tabsWrapper.find('.el-tabs__nav').classes('is-left')).toBe(true)
- expect(tabsWrapper.find('.el-tabs__active-bar').classes('is-left')).toBe(
- true
- )
- expect(tabsWrapper.find('.el-tabs__item').classes('is-left')).toBe(true)
- })
- test('stretch', async () => {
- const tabPosition = ref('bottom')
- const wrapper = mount(() => (
- <Tabs ref="tabs" stretch tab-position={tabPosition.value}>
- <TabPane label="label-1">A</TabPane>
- <TabPane label="label-2">B</TabPane>
- <TabPane label="label-3">C</TabPane>
- <TabPane label="label-4">D</TabPane>
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- await nextTick()
- expect(tabsWrapper.find('.el-tabs__nav').classes('is-stretch')).toBe(true)
- tabPosition.value = 'left'
- await nextTick()
- expect(tabsWrapper.find('.el-tabs__nav').classes('is-stretch')).toBe(false)
- })
- test('tab active bar offset', async () => {
- const tabPosition = ref('bottom')
- const wrapper = mount(() => (
- <Tabs ref="tabs" stretch tab-position={tabPosition.value}>
- <TabPane label="label-1" name="A">
- A
- </TabPane>
- <TabPane label="label-2" name="B">
- B
- </TabPane>
- <TabPane label="label-3" name="C">
- C
- </TabPane>
- <TabPane label="label-4" name="D">
- D
- </TabPane>
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- await nextTick()
- const mockOffsetLeft = vi
- .spyOn(wrapper.find('#tab-C').element as HTMLElement, 'offsetLeft', 'get')
- .mockImplementation(() => 300)
- const mockComputedStyle = vi
- .spyOn(window, 'getComputedStyle')
- .mockReturnValue({ paddingLeft: '0px' } as CSSStyleDeclaration)
- await wrapper.find('#tab-C').trigger('click')
- await nextTick()
- expect(tabsWrapper.find('.el-tabs__active-bar').attributes().style).toMatch(
- 'translateX(300px)'
- )
- tabPosition.value = 'left'
- await nextTick()
- const mockOffsetTop = vi
- .spyOn(wrapper.find('#tab-C').element as HTMLElement, 'offsetTop', 'get')
- .mockImplementation(() => 200)
- await wrapper.find('#tab-A').trigger('click')
- await wrapper.find('#tab-C').trigger('click')
- await nextTick()
- expect(tabsWrapper.find('.el-tabs__active-bar').attributes().style).toMatch(
- 'translateY(200px)'
- )
- mockOffsetLeft.mockRestore()
- mockOffsetTop.mockRestore()
- mockComputedStyle.mockRestore()
- wrapper.unmount()
- })
- test('horizontal-scrollable', async () => {
- // TODO: jsdom not support `clientWidth`.
- })
- test('vertical-scrollable', async () => {
- // TODO: jsdom not support `clientWidth`.
- })
- test('should work with lazy', async () => {
- const activeName = ref('A')
- const wrapper = mount(() => (
- <Tabs v-model={activeName.value} ref="tabs">
- <TabPane label="label-1" lazy name="A">
- A
- </TabPane>
- <TabPane label="label-2" name="B">
- B
- </TabPane>
- <TabPane label="label-3" name="C">
- C
- </TabPane>
- <TabPane label="label-4" lazy name="D">
- D
- </TabPane>
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- await nextTick()
- const navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(wrapper.findAll('.el-tab-pane').length).toBe(3)
- await navItemsWrapper[3].trigger('click')
- expect(wrapper.findAll('.el-tab-pane').length).toBe(4)
- })
- test('before leave', async () => {
- const activeName = ref('tab-B')
- const beforeLeave = () => {
- return new window.Promise<void>((resolve, reject) => {
- reject()
- })
- }
- const wrapper = mount(() => (
- <Tabs ref="tabs" v-model={activeName.value} beforeLeave={beforeLeave}>
- <TabPane name="tab-A" label="label-1">
- A
- </TabPane>
- <TabPane name="tab-B" label="label-2">
- B
- </TabPane>
- <TabPane name="tab-C" label="label-3">
- C
- </TabPane>
- <TabPane name="tab-D" label="label-4">
- D
- </TabPane>
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- const panesWrapper = wrapper.findAllComponents(TabPane)
- await nextTick()
- const navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper[1].classes('is-active')).toBe(true)
- expect(panesWrapper[1].attributes('style')).toBeFalsy()
- await navItemsWrapper[3].trigger('click')
- expect(navItemsWrapper[1].classes('is-active')).toBe(true)
- expect(panesWrapper[1].attributes('style')).toBeFalsy()
- })
- test('keyboard event', async () => {
- const activeName = ref('second')
- const wrapper = mount(() => (
- <Tabs v-model={activeName.value}>
- <TabPane label="label-1" name="first" disabled>
- A
- </TabPane>
- <TabPane label="label-2" name="second">
- B
- </TabPane>
- <TabPane label="label-3" name="third">
- C
- </TabPane>
- <TabPane label="label-4" name="fourth">
- D
- </TabPane>
- </Tabs>
- ))
- await nextTick()
- await wrapper
- .find('#tab-second')
- .trigger('keydown', { code: EVENT_CODE.right })
- expect(activeName.value).toEqual('third')
- await wrapper
- .find('#tab-third')
- .trigger('keydown', { code: EVENT_CODE.right })
- expect(activeName.value).toEqual('fourth')
- await wrapper
- .find('#tab-fourth')
- .trigger('keydown', { code: EVENT_CODE.right })
- expect(activeName.value).toEqual('second')
- await wrapper
- .find('#tab-second')
- .trigger('keydown', { code: EVENT_CODE.left })
- expect(activeName.value).toEqual('fourth')
- })
- test('resize', async () => {
- // TODO: jsdom not support `clientWidth`.
- })
- test('DOM update finished calculating navOffset', async () => {
- const tabs = Array.from({ length: 100 }, (_, i) => i.toString())
- const activeName = ref('0')
- const wrapper = mount(() => (
- <Tabs v-model={activeName.value}>
- {tabs.map((item) => (
- <TabPane key={item} label={item} name={item} />
- ))}
- </Tabs>
- ))
- const tabsWrapper = wrapper.findComponent(Tabs)
- await nextTick()
- const mockOffsetLeft = vi
- .spyOn(
- wrapper.find('#tab-99').element as HTMLElement,
- 'offsetLeft',
- 'get'
- )
- .mockImplementation(() => 100)
- const mockComputedStyle = vi
- .spyOn(window, 'getComputedStyle')
- .mockReturnValue({ paddingLeft: '0px' } as CSSStyleDeclaration)
- await wrapper.find('#tab-99').trigger('click')
- await nextTick()
- expect(tabsWrapper.find('.el-tabs__active-bar').attributes().style).toMatch(
- 'translateX(100px)'
- )
- mockOffsetLeft.mockRestore()
- mockComputedStyle.mockRestore()
- wrapper.unmount()
- })
- test('value type', async () => {
- const activeName = ref<TabPaneName | undefined>(0)
- const handleClick = (tab: TabsPaneContext) => {
- activeName.value = tab.paneName
- }
- const wrapper = mount(() => (
- <Tabs v-model={activeName.value} onTabClick={handleClick}>
- <TabPane name={0} label="label-1">
- A
- </TabPane>
- <TabPane name={1} label="label-2">
- B
- </TabPane>
- <TabPane name={2} label="label-3" ref="pane-click">
- C
- </TabPane>
- <TabPane name={3} label="label-4">
- D
- </TabPane>
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- await nextTick()
- const navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- ;[1, 0, 2, 0, 3, 0, 1].forEach((val) => {
- navItemsWrapper[val].trigger('click')
- expect(activeName.value).toEqual(val)
- })
- })
- test('both number and string for name', async () => {
- const activeName = ref<TabPaneName | undefined>(0)
- const handleClick = (tab: TabsPaneContext) => {
- activeName.value = tab.paneName
- }
- const wrapper = mount(() => (
- <Tabs v-model={activeName.value} onTabClick={handleClick}>
- <TabPane name={0} label="n-0">
- number-0
- </TabPane>
- <TabPane name={'0'} label="s-0">
- string-0
- </TabPane>
- <TabPane name={1} label="n-1">
- number-1
- </TabPane>
- <TabPane name={'1'} label="s-1">
- string-1
- </TabPane>
- </Tabs>
- ))
- const navWrapper = wrapper.findComponent(TabNav)
- await nextTick()
- const navItemsWrapper = navWrapper.findAll('.el-tabs__item')
- expect(navItemsWrapper[0].classes('is-active')).toBe(true)
- expect(navItemsWrapper[1].classes('is-active')).toBe(false)
- await navItemsWrapper[1].trigger('click')
- expect(navItemsWrapper[0].classes('is-active')).toBe(false)
- expect(navItemsWrapper[1].classes('is-active')).toBe(true)
- await navItemsWrapper[2].trigger('click')
- expect(navItemsWrapper[0].classes('is-active')).toBe(false)
- expect(navItemsWrapper[1].classes('is-active')).toBe(false)
- expect(navItemsWrapper[2].classes('is-active')).toBe(true)
- expect(navItemsWrapper[3].classes('is-active')).toBe(false)
- })
- test('tab-pane nested', async () => {
- const wrapper = mount(() => (
- <Tabs>
- <Comp />
- </Tabs>
- ))
- const panesWrapper = wrapper.findAllComponents(TabPane)
- await nextTick()
- expect(panesWrapper.length).toBe(1)
- })
- })
|