Skip to content

Commit

Permalink
tests: add React.js tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatteo committed Dec 19, 2015
1 parent 80f57d2 commit ac18e00
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -18,6 +18,9 @@
"coveralls": "2.11.4",
"istanbul": "0.4.1",
"mocha": "2.3.4",
"react": "0.14.3",
"react-addons-test-utils": "0.14.3",
"react-dom": "0.14.3",
"unexpected": "10.4.0"
},
"scripts": {
Expand Down
60 changes: 58 additions & 2 deletions test/test.js
Expand Up @@ -82,7 +82,6 @@ describe('jsdomify API', () => {

});


describe('Isolation test', () => {

before(() => {
Expand Down Expand Up @@ -119,5 +118,62 @@ describe('jsdomify API', () => {

});

describe('React.js tests', () => {

let getInstance, React, ReactDOM, TestUtils;

before(() => {
jsdomify.create();

React = require('react');
ReactDOM = require('react-dom');
TestUtils = require('react-addons-test-utils');

class ReactComponent extends React.Component {
constructor(props) {
super(props);
this.displayName = 'ReactComponent';
this.state = {
message: props.message || ''
};
}

render() {
return (
<div>
<p onClick={this.handleOnClick.bind(this)} ref="message">{this.state.message}</p>
</div>
);
}

handleOnClick() {
this.setState({message: 'Burritos!'});
}
}

getInstance = (props) => {
return TestUtils.renderIntoDocument(<ReactComponent {...props} />);
}
});

after(() => {
jsdomify.destroy();
});

it('should render a React component using jsdomify', () => {
const instance = getInstance({message: 'Bananas!'});
const messageNode = ReactDOM.findDOMNode(instance.refs.message);
expect(messageNode.textContent, 'to be', 'Bananas!');
});

it('should update a React component on click', () => {
const instance = getInstance({message: 'Bananas!'});
const messageNode = ReactDOM.findDOMNode(instance.refs.message);
expect(messageNode.textContent, 'to be', 'Bananas!');

TestUtils.Simulate.click(messageNode);
expect(messageNode.textContent, 'to be', 'Burritos!');
});
})

});
});

0 comments on commit ac18e00

Please sign in to comment.