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() }) })