Skip to content

Instantly share code, notes, and snippets.

@apsicle
Created October 5, 2017 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apsicle/c369bbd849697231b15df0c2c31cfc77 to your computer and use it in GitHub Desktop.
Save apsicle/c369bbd849697231b15df0c2c31cfc77 to your computer and use it in GitHub Desktop.
import React from 'react';
import { shallow } from 'enzyme';
class TestComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
description: 'asdf123'
};
}
render() {
return (
<div>
<p>{this.state.description}</p>
</div>
)
}
}
test('Should have a defined state', () => {
const wrapper = shallow(<TestComponent />);
console.log(wrapper.state().description); // cannot get property 'description' of undefined
console.log(wrapper.state()); // returns undefined
expect(wrapper).toMatchSnapshot(); // I get <p>asdf123</p> in here, so state seems to be working?
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment