Nested components testing with Enzyme inside of React & Redux

后端 未结 6 1136
甜味超标
甜味超标 2020-12-24 05:55

I have a component SampleComponent that mounts another \"connected component\" (i.e. container). When I try to test SampleComponent by

6条回答
  •  清歌不尽
    2020-12-24 06:44

    You can use name export to solve this problem:

    You should have:

    class SampleComponent extends React.Component{
    ...
       render(){
           
    } } export default connect(mapStateToProps, mapDispatchToProps)(SampleComponent)

    You can add a export before class:

    export class SampleComponent extends React.Component{
    

    and import this component with no redux store:

    import { SampleComponent } from 'your-path/SampleComponent';
    

    With this solution you don't need to import store to your test files.

提交回复
热议问题