test(button): optimization button test (#287)

This commit is contained in:
XieZongChen 2021-06-24 16:01:49 +08:00 committed by GitHub
parent 870386ee38
commit 252eea4f91
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -157,19 +157,31 @@ describe('n-button', () => {
}) })
} }
}) })
const circleReg = const circleStyle = [
/^(?=.*--width: 34px;)(?=.*--padding: initial;)(?=.*--border-radius: 34px;).*$/im '--width: 34px;',
expect(wrapper.find('button').attributes('style')).toMatch(circleReg) '--padding: initial;',
'--border-radius: 34px;'
]
let buttonStyle = wrapper.find('button').attributes('style')
expect(circleStyle.every((i) => buttonStyle.includes(i))).toBe(true)
await wrapper.setProps({ circle: false, round: true }) await wrapper.setProps({ circle: false, round: true })
const roundReg = const roundStyle = [
/^(?=.*--width: initial;)(?=.*--padding: 0 18px;)(?=.*--border-radius: 34px;).*$/im '--width: initial;',
expect(wrapper.find('button').attributes('style')).toMatch(roundReg) '--padding: 0 18px;',
'--border-radius: 34px;'
]
buttonStyle = wrapper.find('button').attributes('style')
expect(roundStyle.every((i) => buttonStyle.includes(i))).toBe(true)
await wrapper.setProps({ circle: false, round: false }) await wrapper.setProps({ circle: false, round: false })
const defaultReg = const defaultStyle = [
/^(?=.*--width: initial;)(?=.*--padding: 0 14px;)(?=.*--border-radius: 3px;).*$/im '--width: initial;',
expect(wrapper.find('button').attributes('style')).toMatch(defaultReg) '--padding: 0 14px;',
'--border-radius: 3px;'
]
buttonStyle = wrapper.find('button').attributes('style')
expect(defaultStyle.every((i) => buttonStyle.includes(i))).toBe(true)
}) })
it('should work with `ghost` prop', () => { it('should work with `ghost` prop', () => {
@ -212,9 +224,13 @@ describe('n-button', () => {
}) })
expect(wrapper.find('button').classes()).toContain('n-button--color') expect(wrapper.find('button').classes()).toContain('n-button--color')
const reg = const colorStyle = [
/^(?=.*--color: #8a2be2;)(?=.*--color-disabled: #8a2be2;)(?=.*--ripple-color: #8a2be2;).*$/im '--color: #8a2be2;',
expect(wrapper.find('button').attributes('style')).toMatch(reg) '--color-disabled: #8a2be2;',
'--ripple-color: #8a2be2;'
]
const buttonStyle = wrapper.find('button').attributes('style')
expect(colorStyle.every((i) => buttonStyle.includes(i))).toBe(true)
}) })
it('should work with `button group`', async () => { it('should work with `button group`', async () => {