Storybook JS Interaction Testing with Enzyme - State Changes being Overidden : <p>I am using storybook to visualize changes to React components after simulating user interaction with enzyme. As a small example, I want a story displaying a component after one of its button has been clicked.</p>

<p>The issue I'm having is the component's constructor gets called twice: once when the component is mounted by enzyme and then after when storybook displays the component. This puts the component back to its default state so any changes following the simulated user interactions are lost.</p>

<p>Here's some code showing the issue. After the story loads, the button component is in the "unclicked" state, even though a click was simulated with enzyme:</p>

<pre><code>import React from 'react';

class SampleComponent extends React.Component {

    constructor(props){
        super(props);
        console.log('constructor');

        this.state = {isClicked: false};
        this.onClick = this.onClick.bind(this);
    }

    onClick(){
        console.log('onClick');
        this.setState({isClicked: true});
    }

    render(){
        const text = (this.state.isClicked)? 'Clicked!' : 'Not Clicked';
        return (
            &lt;div&gt;
                &lt;input type='button' value='Click' onClick={this.onClick} /&gt;
                &lt;p&gt;{text}&lt;/p&gt;
            &lt;/div&gt;
        );
    }
}

export default SampleComponent;
</code></pre>

<p>The story file:</p>

<pre><code>import React from 'react';
import { storiesOf } from '@storybook/react';
import { mount } from 'enzyme';
import { specs, describe, it } from 'storybook-addon-specifications';
import SampleComponent from '../src/SampleComponent';

storiesOf('SampleComponent', module)
    .add('clicked', () =&gt; {

        const comp = &lt;SampleComponent/&gt;;
        specs(() =&gt; describe('clicked', function () {
            it('Should display clicked state message', function () {
                const output = mount(comp);
                output.find('input').simulate('click');
            });
        }));

        return comp;
    });
</code></pre>

<p>The output to console would be:</p>

<pre><code>constructor
onClick
constructor
</code></pre>
