mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-17 04:51:51 +08:00

* perf: change to import-x * feat: add rules * chore: fix rule * chore: fix * chore: fix * chore: fix * style: `pnpm lint:fix` * Revert "style: `pnpm lint:fix`" This reverts commit db0116a288299c507e3cfc4d7a22e2207265d920. * Revert "chore: fix" This reverts commit 69c82a90c01525e38180be4c21e8ef5602512318. * chore: fix * style: `pnpm lint:fix` * fix: lint * chore: `pnpm format`
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import { defineComponent, provide } from 'vue'
|
|
import { mount } from '@vue/test-utils'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { NOOP } from '@element-plus/utils'
|
|
import {
|
|
ElButton,
|
|
buttonGroupContextKey,
|
|
} from '@element-plus/components/button'
|
|
import { formContextKey, formItemContextKey } from '../src/constants'
|
|
|
|
import type { FormContext, FormItemContext } from '../src/types'
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
const mountComponent = (setup = NOOP, options = {}) =>
|
|
mount(
|
|
defineComponent({
|
|
setup,
|
|
render() {
|
|
return <ElButton {...this.$attrs}>{AXIOM}</ElButton>
|
|
},
|
|
}),
|
|
options
|
|
)
|
|
|
|
describe('use-form-item', () => {
|
|
it('should return local value', () => {
|
|
const wrapper = mountComponent()
|
|
expect(wrapper.find('.el-button').exists()).toBe(true)
|
|
})
|
|
|
|
it('should return props.size instead of injected.size', () => {
|
|
const propSize = 'small'
|
|
const wrapper = mountComponent(
|
|
() => {
|
|
provide(formItemContextKey, {
|
|
size: 'large',
|
|
} as FormItemContext)
|
|
},
|
|
{
|
|
props: { size: propSize },
|
|
}
|
|
)
|
|
|
|
expect(wrapper.find(`.el-button--${propSize}`).exists()).toBe(true)
|
|
})
|
|
|
|
it('should return fallback.size instead inject.size', () => {
|
|
const fallbackSize = 'small'
|
|
const wrapper = mountComponent(() => {
|
|
provide(buttonGroupContextKey, {
|
|
size: fallbackSize,
|
|
})
|
|
|
|
provide(formItemContextKey, {
|
|
size: 'large',
|
|
} as FormItemContext)
|
|
})
|
|
|
|
expect(wrapper.find(`.el-button--${fallbackSize}`).exists()).toBe(true)
|
|
})
|
|
|
|
it('should return formItem.size instead form.size', () => {
|
|
const itemSize = 'small'
|
|
const wrapper = mountComponent(() => {
|
|
provide(formItemContextKey, {
|
|
size: itemSize,
|
|
} as FormItemContext)
|
|
|
|
provide(formContextKey, {
|
|
size: 'large',
|
|
} as FormContext)
|
|
})
|
|
|
|
expect(wrapper.find(`.el-button--${itemSize}`).exists()).toBe(true)
|
|
})
|
|
})
|