Skip to content

Commit

Permalink
[Tests] add more render tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 29, 2017
1 parent aa8abc6 commit 7393ba3
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions packages/enzyme-test-suite/test/staticRender-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ describeWithDOM('render', () => {

const context = { name: 'foo' };
const wrapper = render(<SimpleComponent />, { context });

const rootEls = wrapper.children();
expect(rootEls).to.have.lengthOf(1);

expect(rootEls.is('div')).to.equal(true);
expect(rootEls.text()).to.equal('foo');
expect(wrapper.text()).to.equal('foo');

expect(String(wrapper)).to.equal('<div>foo</div>');
expect(String(rootEls)).to.equal('<div>foo</div>');
});

it('can pass context to the child of mounted component', () => {
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
return <span>{this.context.name}</span>;
},
});
const ComplexComponent = createClass({
Expand All @@ -43,9 +53,23 @@ describeWithDOM('render', () => {
};
const context = { name: 'foo' };
const wrapper = render(<ComplexComponent />, { context, childContextTypes });
expect(wrapper.children()).to.have.length(1);
expect(wrapper.children().first().text()).to.equal('foo');

const rootEls = wrapper.children();
expect(rootEls).to.have.length(1);

expect(rootEls.is('div')).to.equal(true);

const children = rootEls.children();
expect(children).to.have.length(1);
expect(children.is('span')).to.equal(true);

expect(children.first().text()).to.equal('foo');

expect(String(wrapper)).to.equal('<div><span>foo</span></div>');
expect(String(rootEls)).to.equal('<div><span>foo</span></div>');
expect(String(children)).to.equal('<span>foo</span>');
});

it('should not throw if context is passed in but contextTypes is missing', () => {
const SimpleComponent = createClass({
render() {
Expand Down

0 comments on commit 7393ba3

Please sign in to comment.