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

The simulate method is Error! #1364

Closed
zenjava opened this issue Nov 15, 2017 · 6 comments
Closed

The simulate method is Error! #1364

zenjava opened this issue Nov 15, 2017 · 6 comments

Comments

@zenjava
Copy link

zenjava commented Nov 15, 2017

link : http://airbnb.io/enzyme/docs/api/ReactWrapper/simulate.html
``

class Foo extends React.Component {
  constructor(props) {
    super(props);
    this.state = { count: 0 };
  }
  render() {
    const { count } = this.state;
    return (
      <div>
        <div className={`clicks-${count}`}>
          {count} clicks
        </div>
        <a href="url" onClick={() => { this.setState({ count: count + 1 }); }}>
          Increment
        </a>
      </div>
    );
  }
}

const wrapper = mount(<Foo />);

expect(wrapper.find('.clicks-0').length).to.equal(1); 
wrapper.find('a').simulate('click');
expect(wrapper.find('.clicks-1').length).to.equal(1) // expected 0 to euqal 1 <===== the error

``

@ljharb
Copy link
Member

ljharb commented Nov 15, 2017

What version of enzyme and react are you using?

What if you wrapper.update() after the simulate?

@zenjava
Copy link
Author

zenjava commented Nov 15, 2017

import React from 'react';
import enzyme, { mount, shallow, } from 'enzyme';
import { expect, } from 'chai';
import Adapter from 'enzyme-adapter-react-16';

enzyme.configure({ adapter: new Adapter(), });


describe('Test', () => {
  it('simulate', () => {
    class Foo extends React.Component {
      constructor (props) {
        super(props);
        this.state = { count: 0, };
      }

      render () {
        const { count, } = this.state;
        return (
          <div>
            <div className={`clicks-${count}`}>
              {count} clicks
            </div>
            <a href="url" onClick={() => {
              this.setState({ count: count + 1, });
            }}>
              Increment
            </a>
          </div>
        );
      }
    }

    const wrapper = mount(<Foo/>);

    expect(wrapper.find('.clicks-0').length).to.equal(1);
    wrapper.find('a').simulate('click');
    wrapper.update();
    expect(wrapper.find('.clicks-1').length).to.equal(1); //<==== is error
  });

});
"react": "16.0.0",
"react-dev-utils": "3.0.2",
"react-dom": "16.0.0",
"react-error-overlay": "1.0.9",

"enzyme": "3.1.1",
"enzyme-adapter-react-16": "1.0.0",

@ljharb
Copy link
Member

ljharb commented Nov 15, 2017

hmm; this might be a duplicate of #1229; does #1229 (comment) help?

@zenjava
Copy link
Author

zenjava commented Nov 30, 2017

I am update enzyme-adapter-react-16 to 1.1.0. Run result is OK.I think that is enzyme bug,but fix 1.1.0.

@zenjava
Copy link
Author

zenjava commented Nov 30, 2017

I see the code, The following code fixes to change the problem.
1.1.0 : const node = findCurrentFiberUsingSlowPath(vnode); --fixed
1.0.0 : const node = vnode.alternate !== null ? vnode.alternate : vnode;

@ljharb
Copy link
Member

ljharb commented Jul 7, 2018

Sounds like v1.1.0 fixed it.

@ljharb ljharb closed this as completed Jul 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants