Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Provide watchQuery to components via connect. (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
dahjelle authored and James Baxley committed Jun 17, 2016
1 parent fdf73d5 commit 27be0a3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 1 or 2 months), so that we can take advantage of SemVer to signify breaking changes from that point on.

### vNEXT

Feature: provide add `watchQuery` to components via `connect`

### v.0.3.8

Bug: Don't use old props on store change change
Expand Down
1 change: 1 addition & 0 deletions src/connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ export default function connect(opts?: ConnectOptions) {
let clientProps = {
mutate: this.client.mutate,
query: this.client.query,
watchQuery: this.client.watchQuery,
} as any;

if (Object.keys(mutations).length) {
Expand Down
29 changes: 29 additions & 0 deletions test/connect/props.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,35 @@ describe('props', () => {

});

it('should pass `ApolloClient.watchQuery` as props.watchQuery', () => {
const store = createStore(() => ({ }));
const client = new ApolloClient();

@connect()
class Container extends React.Component<any, any> {
render() {
return <Passthrough {...this.props} />;
}
};

const wrapper = mount(
<ProviderMock store={store} client={client}>
<Container pass='through' baz={50} />
</ProviderMock>
);


const props = wrapper.find('span').props() as any;

expect(props.watchQuery).to.exist;
try {
expect(props.watchQuery()).to.be.instanceof(Promise);
} catch (e) {
expect(e).to.be.instanceof(TypeError);
};

});

it('should pass mutation methods as props.mutations dictionary', () => {
const store = createStore(() => ({ }));

Expand Down
1 change: 1 addition & 0 deletions test/connect/redux.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe('redux integration', () => {
const reduxProps = assign({}, wrapper.find('span').props(), {
query: undefined,
mutate: undefined,
watchQuery: undefined,
});
const apolloProps = apolloWrapper.find('span').props();

Expand Down

0 comments on commit 27be0a3

Please sign in to comment.