|
| 1 | +import expect from 'expect'; |
| 2 | +import jsdom from 'mocha-jsdom'; |
| 3 | +import React, { PropTypes, Component } from 'react/addons'; |
| 4 | +import { createRedux } from '../../src'; |
| 5 | +import { provide, Provider } from '../../src/react'; |
| 6 | + |
| 7 | +const { TestUtils } = React.addons; |
| 8 | + |
| 9 | +describe('React', () => { |
| 10 | + describe('provide', () => { |
| 11 | + jsdom(); |
| 12 | + |
| 13 | + class Child extends Component { |
| 14 | + static contextTypes = { |
| 15 | + redux: PropTypes.object.isRequired |
| 16 | + } |
| 17 | + |
| 18 | + render() { |
| 19 | + return <div />; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + it('wraps component with Provider', () => { |
| 24 | + const redux = createRedux({ test: () => 'test' }); |
| 25 | + |
| 26 | + @provide(redux) |
| 27 | + class Container extends Component { |
| 28 | + render() { |
| 29 | + return <Child {...this.props} />; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + const container = TestUtils.renderIntoDocument(<Container pass="through" />); |
| 34 | + const child = TestUtils.findRenderedComponentWithType(container, Child); |
| 35 | + expect(child.props.pass).toEqual('through'); |
| 36 | + expect(() => TestUtils.findRenderedComponentWithType(container, Provider)) |
| 37 | + .toNotThrow(); |
| 38 | + expect(child.context.redux).toBe(redux); |
| 39 | + }); |
| 40 | + |
| 41 | + it('sets displayName correctly', () => { |
| 42 | + @provide(createRedux({ test: () => 'test' })) |
| 43 | + class Container extends Component { |
| 44 | + render() { |
| 45 | + return <div />; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + expect(Container.displayName).toBe('Provider(Container)'); |
| 50 | + }); |
| 51 | + }); |
| 52 | +}); |
0 commit comments