element-plus/packages/hooks/__tests__/use-form-item.test.tsx
三咲智子 1d13ebb05d
feat: drop jest (#7248)
* feat: drop jest

* test: remove ssr

* test: rename

* chore: update tsconfig
2022-04-19 16:51:44 +08:00

81 lines
2.0 KiB
TypeScript

import { defineComponent, provide } from 'vue'
import { NOOP } from '@vue/shared'
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import { ElButton } from '@element-plus/components'
import {
buttonGroupContextKey,
formContextKey,
formItemContextKey,
} from '@element-plus/tokens'
import type {
ButtonGroupContext,
FormContext,
FormItemContext,
} from '@element-plus/tokens'
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' })
},
{
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,
} as ButtonGroupContext)
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)
})
})