Skip to content

Commit

Permalink
Add a test for overwriting a subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
BBB committed Oct 6, 2016
1 parent 95c55e0 commit e82fcb1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/components/subscribe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,35 @@ describe('#mapDataToProps(array):', (test) => {
})(() => <div></div>);
mount(<SubscribedComponent store={store} client={horizon} />);
});

test('it should use the last subscription for the same name', (t) => {
t.plan(1);
const store = createStore((state) => state);
const widgets2 = [{ id: 2, }];
const horizon = HorizonMock();
const SubscribedComponent = subscribe({
mapDataToProps: [
{
name: 'widgets',
query: () => {
const hz = HorizonMock({ data: [{ id: 1 }] });
return hz('widgets');
}
},
{
name: 'widgets',
query: () => {
const hz = HorizonMock({ data: widgets2 });
return hz('widget2');
}
}
]
})((props) => {
t.true(props.widgets === widgets2);
return null;
});
mount(<SubscribedComponent store={store} client={horizon} />);
});
});

describe('#mapDataToProps(plainObject):', (test) => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/test/HorizonMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const horizonSub = (data) => ({
function HorizonMock(opts = {}) {
const hzInterface = () => ({
findAll() {},
_query: Math.random(),
...horizonSub(opts.data)
});

Expand Down

0 comments on commit e82fcb1

Please sign in to comment.