Files
element-plus/packages/components/select/__tests__/options.test.tsx
kooriookami 5844947198 refactor(components): [select & select-v2] Refactor components (#15352)
* 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
2024-01-10 11:14:58 +08:00

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>
)),
})
})
})