From 252eea4f91e5951b7b219869ec6b0773c675ea75 Mon Sep 17 00:00:00 2001 From: XieZongChen <46394163+amadeus711@users.noreply.github.com> Date: Thu, 24 Jun 2021 16:01:49 +0800 Subject: [PATCH] test(button): optimization button test (#287) --- src/button/tests/Button.spec.tsx | 40 ++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/button/tests/Button.spec.tsx b/src/button/tests/Button.spec.tsx index ce3ef90f4..4971f8aef 100644 --- a/src/button/tests/Button.spec.tsx +++ b/src/button/tests/Button.spec.tsx @@ -157,19 +157,31 @@ describe('n-button', () => { }) } }) - const circleReg = - /^(?=.*--width: 34px;)(?=.*--padding: initial;)(?=.*--border-radius: 34px;).*$/im - expect(wrapper.find('button').attributes('style')).toMatch(circleReg) + const circleStyle = [ + '--width: 34px;', + '--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 }) - const roundReg = - /^(?=.*--width: initial;)(?=.*--padding: 0 18px;)(?=.*--border-radius: 34px;).*$/im - expect(wrapper.find('button').attributes('style')).toMatch(roundReg) + const roundStyle = [ + '--width: initial;', + '--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 }) - const defaultReg = - /^(?=.*--width: initial;)(?=.*--padding: 0 14px;)(?=.*--border-radius: 3px;).*$/im - expect(wrapper.find('button').attributes('style')).toMatch(defaultReg) + const defaultStyle = [ + '--width: initial;', + '--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', () => { @@ -212,9 +224,13 @@ describe('n-button', () => { }) expect(wrapper.find('button').classes()).toContain('n-button--color') - const reg = - /^(?=.*--color: #8a2be2;)(?=.*--color-disabled: #8a2be2;)(?=.*--ripple-color: #8a2be2;).*$/im - expect(wrapper.find('button').attributes('style')).toMatch(reg) + const colorStyle = [ + '--color: #8a2be2;', + '--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 () => {