Skip to content

Commit 612681b

Browse files
committed
Tests for @provide decorator
1 parent c22cde1 commit 612681b

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/components/createProvideDecorator.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import getDisplayName from '../utils/getDisplayName';
22

33
export default function createProvideDecorator(React, Provider) {
4+
const { Component } = React;
5+
46
return function provide(redux) {
5-
return DecoratedComponent => class ProviderDecorator {
7+
return DecoratedComponent => class ProviderDecorator extends Component {
68
static displayName = `Provider(${getDisplayName(DecoratedComponent)})`;
79

810
render() {
911
return (
1012
<Provider redux={redux}>
11-
{props => <DecoratedComponent {...this.props} {...props} />}
13+
{() => <DecoratedComponent {...this.props} />}
1214
</Provider>
1315
);
1416
}

test/components/provide.spec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)