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

Commit

Permalink
MockNetworkInterface match mock requests regardless of variable order (
Browse files Browse the repository at this point in the history
…#973)

* MockNetworkInterface match regardless of variable order

* update changelog
  • Loading branch information
L1fescape authored and James Baxley committed Aug 13, 2017
1 parent 83a74ed commit 7308d20
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change log

### vNext
- MockNetworkInterface match mock requests regardless of variable order [#973](https://github.com/apollographql/react-apollo/pull/973)

### 1.4.11
- Replace string refs with callback refs [#908](https://github.com/apollographql/react-apollo/pull/908)
Expand Down
5 changes: 3 additions & 2 deletions src/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,10 @@ export class MockSubscriptionNetworkInterface extends MockNetworkInterface

function requestToKey(request: ParsedRequest): string {
const queryString = request.query && print(request.query);
return JSON.stringify({
const requestKey = {
variables: request.variables || {},
debugName: request.debugName,
query: queryString,
});
};
return JSON.stringify(requestKey, Object.keys(requestKey).sort());
}
53 changes: 53 additions & 0 deletions test/react-web/client/graphql/queries/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,59 @@ describe('queries', () => {
);
});

it("doesn't care about the order of variables in a request", done => {
const query = gql`
query people($first: Int, $jedi: Boolean) {
allPeople(first: $first, jedi: $jedi) {
people {
name
}
}
}
`;
const data = { allPeople: { people: [{ name: 'Luke Skywalker' }] } };
const variables = { first: 1, jedi: true };
const mocks = [
{
request: {
query,
variables,
},
result: {
data,
},
},
];
const networkInterface = mockNetworkInterface.apply(null, mocks);
const client = new ApolloClient({ networkInterface, addTypename: false });
const options = {
options: {
variables: {
jedi: true,
first: 1,
},
},
};

@graphql(query, options)
class Container extends React.Component<any, any> {
componentWillReceiveProps(props) {
expect(props.data.loading).toBe(false);
expect(props.data.allPeople).toEqual(data.allPeople);
done();
}
render() {
return null;
}
}

renderer.create(
<ApolloProvider client={client}>
<Container />
</ApolloProvider>,
);
});

it('allows falsy values in the mapped variables from props', done => {
const query = gql`
query people($first: Int) {
Expand Down

0 comments on commit 7308d20

Please sign in to comment.