lundi 4 mai 2020

Jest and Enzyme. New tags are not being added on button click

I have class which creates new tags on button click

class Editor extends Component {
    constructor(props) {
        super(props);
        this.state = {
            html: [],
        };
    }
    render() {
        return (
            <div>
                <Button onClick={() => this.setState({html:[<div><div>1</div><div>2</div></div>]})} test-key={'expandButton'}>
                    expandNodes
                </Button>
                {html.length > 0 &&
                    <Row>
                        {html.map(object => (
                            <div>
                                {object}
                            </div>
                        ))}
                    </Row>
                }    
            </div>
        );                                     
    }
}

I have a Edtior.test.js:

describe('Editor', () => {
    it('should render tags when button clicked', () => {
        let wrapper = mount(<Editor/>)
        let button = wrapper.find({'test-key':'expandButton'})
        console.log(wrapper.find('div').length)
        button.props().onClick()
        console.log(wrapper.find('div').length)
    })
})

onClick() is being called and html also changes. However quantity of 'div's is not changing

Aucun commentaire:

Enregistrer un commentaire