Skip to content

Commit

Permalink
adjusting test types
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkis committed Feb 17, 2017
1 parent a3e8715 commit 6a02d0a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
2 changes: 0 additions & 2 deletions packages/prism-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"version": "0.1.0",
"description": "Prism bindings for React-Redux",
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"build:commonjs": "tsc -p ./ --module commonjs --outDir lib",
Expand Down
36 changes: 27 additions & 9 deletions packages/prism-react/src/__tests__/enhanceComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@ interface SuperModel {
nested: NestedModel
};

interface NestTestingModel {
foo: SuperModel
};

interface Action {
type: string
};

const HelloWorld = ({ name } : HelloWorldProps) => <div>Hello {name}!</div>;
const FooBar = ({ onClick, name } : FooBarProps) => <button onClick={onClick}>{name}</button>;

const EnhancedHelloWorld = enhanceComponent<NestedModel>(connect(
const EnhancedHelloWorld = enhanceComponent<SuperModel, NestedModel>(connect(
state => ({
name: state.name
})
)(HelloWorld));

const EnhancedFooBar = enhanceComponent(connect(
const EnhancedFooBar = enhanceComponent<SuperModel, NestedModel>(connect(
({ name }) => ({ name }),
{
onClick: () => ({ type: 'Bar' })
Expand Down Expand Up @@ -72,30 +76,44 @@ describe('enhanceComponent', () => {
});

it('should allow wrapping all the outgoing actions in redux store context', () => {
const store = createStore((value : number = 0, { type } : Action) => {
const store = createStore((state : SuperModel = {
nested: {
name: ''
}
}, { type } : Action) => {
if (type === 'Foo.Bar') {
return 42;
return {
...state,
nested: {
...state.nested,
name: '42'
}
};
} else {
return value;
return state;
}
});

const component = mount(
<Provider store={store}>
<EnhancedFooBar
selector={value => value}
selector={value => value.nested}
wrapper={type => `Foo.${type}`}
/>
</Provider>
);

component.find('button').simulate('click');

expect(store.getState()).toEqual(42);
expect(store.getState()).toEqual({
nested: {
name: '42'
}
});
});

it('should allow nested wrapping & selectors', () => {
const appState = {
const appState : NestTestingModel = {
foo: {
nested: {
name: 'Tomas Weiss'
Expand Down Expand Up @@ -126,7 +144,7 @@ describe('enhanceComponent', () => {
/>
);

const EnhancedRoot = enhanceComponent(connect(
const EnhancedRoot = enhanceComponent<NestTestingModel, SuperModel>(connect(
state => state
)(Root));

Expand Down
2 changes: 0 additions & 2 deletions packages/prism-redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"version": "0.1.0",
"description": "Prism bindings for Redux",
"main": "lib/index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"typings": "lib/index.d.ts",
"scripts": {
"build:commonjs": "tsc -p ./ --module commonjs --outDir lib",
Expand Down
2 changes: 1 addition & 1 deletion packages/prism/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "prism",
"version": "0.1.0",
"description": "Prism",
"description": "React / Redux action composition made simple",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"scripts": {
Expand Down

0 comments on commit 6a02d0a

Please sign in to comment.