Last active
May 1, 2016 09:37
-
-
Save pahund/014c1c82b05ca3bc563e5ba25cfdb5ac to your computer and use it in GitHub Desktop.
This test is derived from the example for simulate from the Enzyme documentation. It fails with an "Invariant Violation" exception, which I suspect to be a bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* enzymeSimulateTest.js | |
* | |
* @author <a href="mailto:[email protected]">Patrick Hund</a> | |
* @since 29 Apr 2016 | |
*/ | |
import React, { Component } from "react"; | |
import { mount } from "enzyme"; | |
import { expect } from "chai"; | |
function IncrementButton(props) { | |
return <button onClick={props.onClick}>Increment</button>; | |
} | |
class Foo extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { count: 0 }; | |
} | |
render() { | |
const { count } = this.state; | |
return ( | |
<div> | |
<div className={`clicks-${count}`}> | |
{count} clicks | |
</div> | |
<IncrementButton onClick={() => this.setState({ count: count + 1 })} /> | |
</div> | |
); | |
} | |
} | |
const wrapper = mount(<Foo />); | |
expect(wrapper.find(".clicks-0").length).to.equal(1); | |
wrapper.find("IncrementButton").simulate("click"); | |
expect(wrapper.find(".clicks-1").length).to.equal(1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment