From f3063dd7f260d1b549cb255c680c3c2595b59a40 Mon Sep 17 00:00:00 2001 From: jimczj Date: Wed, 21 Nov 2018 00:05:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(rate):=20=E4=BF=AE=E6=94=B9pxTransform?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/rate/index.js | 17 ++++++++++------- src/components/rate/index.test.js | 12 ++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/components/rate/index.js b/src/components/rate/index.js index 1187b0989..a51da55ff 100644 --- a/src/components/rate/index.js +++ b/src/components/rate/index.js @@ -38,13 +38,19 @@ export default class AtRate extends AtComponent { onChange: PropTypes.func } - handleClick (i) { - this.props.onChange(i + 1, ...arguments) + constructor () { + super(...arguments) + if (process.env.NODE_ENV === 'test') { + Taro.initPxTransform({ designWidth: 750 }) + } + } + + handleClick () { + this.props.onChange(...arguments) } render () { const { - isTest, customStyle, className, value, @@ -53,9 +59,6 @@ export default class AtRate extends AtComponent { margin } = this.props - if (isTest) { - Taro.initPxTransform({ designWidth: 750 }) - } const iconStyle = { marginRight: Taro.pxTransform(margin) } @@ -83,7 +86,7 @@ export default class AtRate extends AtComponent { className={cls} key={i} style={iconStyle} - onClick={this.handleClick.bind(this, i)} + onClick={this.handleClick.bind(this, i + 1)} > diff --git a/src/components/rate/index.test.js b/src/components/rate/index.test.js index f2f5c8180..9f30653f2 100644 --- a/src/components/rate/index.test.js +++ b/src/components/rate/index.test.js @@ -10,32 +10,32 @@ describe('AtRate Snap', () => { }) it('render AtRate -- props customStyle', () => { - const componet = renderToString() + const componet = renderToString() expect(componet).toMatchSnapshot() }) it('render AtRate -- props className', () => { - const componet = renderToString() + const componet = renderToString() expect(componet).toMatchSnapshot() }) it('render AtRate -- props size', () => { - const componet = renderToString() + const componet = renderToString() expect(componet).toMatchSnapshot() }) it('render AtRate -- props value', () => { - const componet = renderToString() + const componet = renderToString() expect(componet).toMatchSnapshot() }) it('render AtRate -- props max', () => { - const componet = renderToString() + const componet = renderToString() expect(componet).toMatchSnapshot() }) it('render AtRate -- props margin', () => { - const componet = renderToString() + const componet = renderToString() expect(componet).toMatchSnapshot() }) })