How to Unit Test React-Redux Connected Components?

前端 未结 5 2184
礼貌的吻别
礼貌的吻别 2020-11-27 14:40

I am using Mocha, Chai, Karma, Sinon, Webpack for Unit tests.

I followed this link to configure my testing environment for React-Redux Code.

How to implement

5条回答
  •  误落风尘
    2020-11-27 15:25

    A prettier way to do this, is to export both your plain component, and the component wrapped in connect. The named export would be the component, the default is the wrapped component:

    export class Sample extends Component {
    
        render() {
            let { verification } = this.props;
            return (
                

    This is my awesome component.

    ); } } const select = (state) => { return { verification: state.verification } } export default connect(select)(Sample);

    In this way you can import normally in your app, but when it comes to testing you can import your named export using import { Sample } from 'component'.

提交回复
热议问题