Skip to content

Commit 47a7df7

Browse files
committed
Add a test and some style fixes
1 parent 9992827 commit 47a7df7

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/components/createConnect.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default function createConnect(React) {
3131
const bindDispatch = isPlainObject(dispatchBinder) ?
3232
wrapActionCreators(dispatchBinder) :
3333
dispatchBinder;
34-
3534
const merge = mergeHandler;
3635

3736
return DecoratedComponent => class ConnectDecorator extends Component {

test/components/connect.spec.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@ describe('React', () => {
5353
expect(container.context.store).toBe(store);
5454
});
5555

56-
it('should wrap the component into Provider', () => {
56+
it('should pass the state and the props given component', () => {
5757
const store = createStore(() => ({
58-
foo: 'bar'
58+
foo: 'bar',
59+
baz: 42,
60+
hello: 'world'
5961
}));
6062

61-
@connect(state => state)
63+
@connect(({ foo, baz }) => ({ foo, baz }))
6264
class Container extends Component {
6365
render() {
6466
return <div {...this.props} />;
@@ -67,12 +69,14 @@ describe('React', () => {
6769

6870
const container = TestUtils.renderIntoDocument(
6971
<Provider store={store}>
70-
{() => <Container pass='through' />}
72+
{() => <Container pass='through' baz={50} />}
7173
</Provider>
7274
);
7375
const div = TestUtils.findRenderedDOMComponentWithTag(container, 'div');
7476
expect(div.props.pass).toEqual('through');
7577
expect(div.props.foo).toEqual('bar');
78+
expect(div.props.baz).toEqual(42);
79+
expect(div.props.hello).toEqual(undefined);
7680
expect(() =>
7781
TestUtils.findRenderedComponentWithType(container, Container)
7882
).toNotThrow();
@@ -81,7 +85,7 @@ describe('React', () => {
8185
it('should subscribe to the store changes', () => {
8286
const store = createStore(stringBuilder);
8387

84-
@connect(state => ({string: state}) )
88+
@connect(state => ({ string: state }) )
8589
class Container extends Component {
8690
render() {
8791
return <div {...this.props}/>;
@@ -128,14 +132,15 @@ describe('React', () => {
128132
}
129133
};
130134
}
131-
componentDidMount() {
132135

136+
componentDidMount() {
133137
// Simulate deep object mutation
134138
this.state.bar.baz = 'through';
135139
this.setState({
136140
bar: this.state.bar
137141
});
138142
}
143+
139144
render() {
140145
return (
141146
<Provider store={store}>
@@ -163,11 +168,13 @@ describe('React', () => {
163168

164169
@connect(
165170
state => ({stateThing: state}),
166-
dispatch => ({doSomething: (whatever) => dispatch(doSomething(whatever)) }),
171+
dispatch => ({
172+
doSomething: (whatever) => dispatch(doSomething(whatever))
173+
}),
167174
(stateProps, actionProps, parentProps) => ({
168175
...stateProps,
169176
...actionProps,
170-
mergedDoSomething: (thing) => {
177+
mergedDoSomething(thing) {
171178
const seed = stateProps.stateThing === '' ? 'HELLO ' : '';
172179
actionProps.doSomething(seed + thing + parentProps.extra);
173180
}

0 commit comments

Comments
 (0)