|
| 1 | +import expect from 'expect'; |
| 2 | +import jsdomReact from './jsdomReact'; |
| 3 | +import React, { PropTypes, Component } from 'react/addons'; |
| 4 | +import { createStore } from 'redux'; |
| 5 | +import { provide, Provider } from '../../src/index'; |
| 6 | + |
| 7 | +const { TestUtils } = React.addons; |
| 8 | + |
| 9 | +describe('React', () => { |
| 10 | + describe('provide', () => { |
| 11 | + jsdomReact(); |
| 12 | + |
| 13 | + class Child extends Component { |
| 14 | + static contextTypes = { |
| 15 | + store: PropTypes.object.isRequired |
| 16 | + } |
| 17 | + |
| 18 | + render() { |
| 19 | + return <div />; |
| 20 | + } |
| 21 | + } |
| 22 | + |
| 23 | + it('should wrap the component into Provider', () => { |
| 24 | + const store = createStore({}); |
| 25 | + |
| 26 | + @provide(store) |
| 27 | + class Container extends Component { |
| 28 | + render() { |
| 29 | + return <Child {...this.props} />; |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + const container = TestUtils.renderIntoDocument( |
| 34 | + <Container pass='through' /> |
| 35 | + ); |
| 36 | + const child = TestUtils.findRenderedComponentWithType(container, Child); |
| 37 | + expect(child.props.pass).toEqual('through'); |
| 38 | + expect(() => |
| 39 | + TestUtils.findRenderedComponentWithType(container, Provider) |
| 40 | + ).toNotThrow(); |
| 41 | + expect(child.context.store).toBe(store); |
| 42 | + }); |
| 43 | + |
| 44 | + it('sets the displayName correctly', () => { |
| 45 | + @provide(createStore({})) |
| 46 | + class Container extends Component { |
| 47 | + render() { |
| 48 | + return <div />; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + expect(Container.displayName).toBe('Provider(Container)'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should expose the wrapped component as DecoratedComponent', () => { |
| 56 | + class Container extends Component { |
| 57 | + render() { |
| 58 | + return <div />; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + const decorator = provide(state => state); |
| 63 | + const decorated = decorator(Container); |
| 64 | + |
| 65 | + expect(decorated.DecoratedComponent).toBe(Container); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments