Skip to content

Commit

Permalink
feat(Componentize): make sure render works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Sep 26, 2015
1 parent 58a0f1b commit 1f2227d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/components/__tests__/Componentize.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,53 @@ describe(`React`, () => {
comp.render();
});
});

context(`render`, () => {
it(`should pass props and undefined state`, (done) => {
const render = (props, state, actions) => {
expect(props).toBeA(`object`);
expect(props).toEqual({
name: `Tom Chen`,
});

expect(state).toBeA(`undefined`);
done();
};

const ReduxComponent = Componentize(createStore, () => undefined, noop, noop)(render);
const comp = new ReduxComponent({
name: `Tom Chen`,
});

comp.render();
});

it(`should pass props and initial state from reducer`, (done) => {
const render = (props, state, actions) => {
expect(props).toBeA(`object`);
expect(props).toEqual({
name: `Tom Chen`,
});

expect(state).toBeA(`object`);
expect(state).toEqual({
age: 0,
});
done();
};

const initialState = {
age: 0,
};

const ReduxComponent = Componentize(createStore, () => initialState, noop, noop)(render);
const comp = new ReduxComponent({
name: `Tom Chen`,
});

comp.render();
});
});
});
});
});
2 changes: 2 additions & 0 deletions src/components/createComponentize.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default function createComponentize (React) {
};

this.eventActions = mapDispatchToActions(this.store.dispatch);

this.state = this.store.getState();
}

componentWillMount () {
Expand Down

0 comments on commit 1f2227d

Please sign in to comment.