2016-09-06 10 views
1

私はコンポーネントデフをテストしようとしていますが、私は得られません。AVAで@decorator(redux-connect)を使用したテストコンポーネントのデコレーターとは?

例:

import React, { Component } from 'react' 
import { connect } from 'react-redux' 

@connect(({ user }) => ({ user })) 
export class Componente extends Component { 
    render() { 
     return <div>hello {this.props.user}</div> 
    } 
} 

例試験:

import test from 'ava' 
import Component from './Component' 
import { mount } from 'enzyme' 

test('<Component />', t => { 
    let wrapper = mount(<Component />) // the connect's redux create a wrapper component :(
}) 

非装飾コンポーネントをテストすることができますか?どうやって?

+0

デコレータは*提案*ですが、ES7には含まれていません。 –

答えて

2

connectで生成されたラッパークラスは、内部コンポーネントクラスをWrappedComponentという名前の静的フィールドとして公開しているため、別々にテストすることができます。 https://github.com/reactjs/react-redux/blob/master/docs/api.md#static-propertiesを参照してください。

+0

コンポーネントで@decoratorを使用した後で、コンポーネントを分離できないのですか? – Fuechter

関連する問題