/
staticRender-spec.jsx
59 lines (55 loc) · 1.81 KB
/
staticRender-spec.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react';
import PropTypes from 'prop-types';
import { expect } from 'chai';
import { describeWithDOM, describeIf } from './_helpers';
import { render } from '../src/';
import { REACT013 } from '../src/version';
import { createClass } from './react-compat'
describeWithDOM('render', () => {
describeIf(!REACT013, 'context', () => {
it('can pass in context', () => {
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
},
});
const context = { name: 'foo' };
const wrapper = render(<SimpleComponent />, { context });
expect(wrapper.text()).to.equal('foo');
});
it('can pass context to the child of mounted component', () => {
const SimpleComponent = createClass({
contextTypes: {
name: PropTypes.string,
},
render() {
return <div>{this.context.name}</div>;
},
});
const ComplexComponent = createClass({
render() {
return <div><SimpleComponent /></div>;
},
});
const childContextTypes = {
name: PropTypes.string.isRequired,
};
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');
});
it('should not throw if context is passed in but contextTypes is missing', () => {
const SimpleComponent = createClass({
render() {
return <div>{this.context.name}</div>;
},
});
const context = { name: 'foo' };
expect(() => render(<SimpleComponent />, { context })).to.not.throw(Error);
});
});
});