mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* refactor(components): [select&select-v2] refactor components * refactor(components): [select-v2] * refactor(components): update * refactor(components): update * refactor(components): [select-v2] update * refactor(components): update * refactor(components): update * refactor(components): update type * refactor(components): update * refactor(components): update * refactor(components): update style * refactor(components): update docs * refactor(components): update * refactor(components): fix #15323 * refactor(theme-chalk): update * refactor(components): update * refactor(components): update * refactor(components): update * refactor(components): fix bugs * fix(components): fix issue * fix(components): update * fix(components): fix some bug * feat(components): update * feat(components): add tag slot * feat(components): update * fix(components): update * style(theme-chalk): update style * fix(theme-chalk): update * feat(theme-chalk): update * fix(components): update * feat: update * feat: update * feat: update * feat(components): update
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
import { defineComponent, nextTick } from 'vue'
|
|
import { mount } from '@vue/test-utils'
|
|
import { afterEach, describe, it } from 'vitest'
|
|
import Options from '../src/options'
|
|
|
|
import type { VueWrapper } from '@vue/test-utils'
|
|
|
|
describe('options', () => {
|
|
let wrapper: ReturnType<typeof mount>
|
|
|
|
const ElOptionStub = defineComponent({
|
|
name: 'ElOption',
|
|
props: {
|
|
label: String,
|
|
},
|
|
template: '<div></div>',
|
|
})
|
|
|
|
const getLabel = (i: number | string) => `label-${i}`
|
|
|
|
const ElOptionGroupStub = defineComponent({
|
|
name: 'ElOptionGroup',
|
|
template: '<div><slot /></div>',
|
|
})
|
|
|
|
const samples = Array.from({ length: 3 })
|
|
|
|
const createWrapper = (slots = {}) => {
|
|
wrapper = mount((_, { slots }) => <Options>{slots?.default?.()}</Options>, {
|
|
global: {
|
|
components: {
|
|
ElOption: ElOptionStub,
|
|
ElOptionGroup: ElOptionGroupStub,
|
|
},
|
|
},
|
|
slots,
|
|
}) as VueWrapper<any>
|
|
}
|
|
|
|
afterEach(() => {
|
|
wrapper.unmount()
|
|
})
|
|
|
|
it('renders emit correct options', async () => {
|
|
createWrapper({
|
|
default: () =>
|
|
samples.map((_, i) => <ElOptionStub label={getLabel(i)} />),
|
|
})
|
|
|
|
await nextTick()
|
|
})
|
|
|
|
it('renders emit correct options with option group', async () => {
|
|
createWrapper({
|
|
default: () =>
|
|
samples.map((_, i) => (
|
|
<ElOptionGroupStub label={getLabel(i)}>
|
|
{{
|
|
default: () =>
|
|
samples.map((_, j) => (
|
|
<ElOptionStub
|
|
label={getLabel(`${i}-${j}`)}
|
|
value={j}
|
|
></ElOptionStub>
|
|
)),
|
|
}}
|
|
</ElOptionGroupStub>
|
|
)),
|
|
})
|
|
})
|
|
})
|