Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Props not updated when shouldComponentUpdate returns false (lifecycleExperimental: true) #805

Closed
wicked539 opened this issue Feb 10, 2017 · 2 comments · Fixed by #807
Closed

Comments

@wicked539
Copy link

When shallow rendering a component using lifecycleExperimental: true, it seems that it's props are not updated if it's shouldComponentUpdate()-method returns false. Since the props are updated in production and when using standard shallow rendering, I'm guessing that this would be the desired behavior.

import React from 'react';
import chai from 'chai';
import { shallow } from 'enzyme';

class MyDummyComponent extends React.Component {

    shouldComponentUpdate() {
        return false;
    }

    render() {
        return (<div>hello world.</div>)
    }
}

describe('<MyDummyComponent/>', function () {

    it('fails to update props with lifecycleExperimental: true', function () {
        let props = {
            foo: 'bar'
        }

        const wrapper = shallow(<MyDummyComponent {...props} />, { lifecycleExperimental: true });

        chai.expect(wrapper.instance().props.foo).to.equal('bar');

        props.foo = 'baz';

        wrapper.setProps(props);

        // fails when shouldComponentUpdate returns false, succeeds otherwise
        chai.expect(wrapper.instance().props.foo).to.equal('baz');
    });

    it('updates props with "normal" shallow rendering', function () {
        let props = {
            foo: 'bar'
        }

        const wrapper = shallow(<MyDummyComponent {...props} />);

        chai.expect(wrapper.instance().props.foo).to.equal('bar');

        props.foo = 'baz';

        wrapper.setProps(props);

        chai.expect(wrapper.instance().props.foo).to.equal('baz');
    });
});

I am using React 15.4.2 & Enzyme 2.7.1.

@koba04
Copy link
Contributor

koba04 commented Feb 13, 2017

I'll take on this.

@wicked539
Copy link
Author

Great, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants