test(button): optimization (#1187)

This commit is contained in:
XieZongChen 2021-09-16 02:27:24 -05:00 committed by GitHub
parent c1e2946b59
commit ee0265a275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,22 +37,15 @@ describe('n-button', () => {
}) })
it('should work with `type` prop', async () => { it('should work with `type` prop', async () => {
const wrapper = mount(NButton) ;(['primary', 'info', 'success', 'warning', 'error'] as const).forEach(
(type) => {
await wrapper.setProps({ type: 'primary' }) const wrapper = mount(NButton, { props: { type: type } })
expect(wrapper.find('button').classes()).toContain('n-button--primary-type') expect(wrapper.find('button').classes()).toContain(
`n-button--${type}-type`
await wrapper.setProps({ type: 'info' }) )
expect(wrapper.find('button').classes()).toContain('n-button--info-type') wrapper.unmount()
}
await wrapper.setProps({ type: 'success' }) )
expect(wrapper.find('button').classes()).toContain('n-button--success-type')
await wrapper.setProps({ type: 'warning' })
expect(wrapper.find('button').classes()).toContain('n-button--warning-type')
await wrapper.setProps({ type: 'error' })
expect(wrapper.find('button').classes()).toContain('n-button--error-type')
}) })
it('should work with `dashed` prop', async () => { it('should work with `dashed` prop', async () => {
@ -70,19 +63,11 @@ describe('n-button', () => {
}) })
it('should work with `size` prop', async () => { it('should work with `size` prop', async () => {
const wrapper = mount(NButton) ;(['tiny', 'small', 'medium', 'large'] as const).forEach((size) => {
const wrapper = mount(NButton, { props: { size: size } })
await wrapper.setProps({ size: 'tiny' })
expect(wrapper.find('button').attributes('style')).toMatchSnapshot()
await wrapper.setProps({ size: 'small' })
expect(wrapper.find('button').attributes('style')).toMatchSnapshot()
await wrapper.setProps({ size: 'medium' })
expect(wrapper.find('button').attributes('style')).toMatchSnapshot()
await wrapper.setProps({ size: 'large' })
expect(wrapper.find('button').attributes('style')).toMatchSnapshot() expect(wrapper.find('button').attributes('style')).toMatchSnapshot()
wrapper.unmount()
})
}) })
it('should work with `text` prop', () => { it('should work with `text` prop', () => {