Skip to content

Commit

Permalink
Reproduce #647
Browse files Browse the repository at this point in the history
Post-mutation failing store reading during updateQueries.
  • Loading branch information
rricard committed Sep 15, 2016
1 parent 5901aa4 commit 945cb72
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions test/mutationResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('mutation results', () => {
return state;
}

function setup(...mockedResponses: any[]) {
function setupObsHandle(...mockedResponses: any[]) {
networkInterface = mockNetworkInterface({
request: { query },
result,
Expand All @@ -137,10 +137,13 @@ describe('mutation results', () => {
},
});

const obsHandle = client.watchQuery({
return client.watchQuery({
query,
});
}

function setup(...mockedResponses: any[]) {
const obsHandle = setupObsHandle(...mockedResponses);
return obsHandle.result();
};

Expand Down Expand Up @@ -645,6 +648,32 @@ describe('mutation results', () => {
});
});

it('does not fail if the query did not complete correctly', () => {
const obsHandle = setupObsHandle({
request: { query: mutation },
result: mutationResult,
});
const subs = obsHandle.subscribe({
next: () => null,
});
// Cancel the query right away!
subs.unsubscribe();
return client.mutate({
mutation,
updateQueries: {
todoList: (prev, options) => {
const mResult = options.mutationResult as any;
assert.equal(mResult.data.createTodo.id, '99');
assert.equal(mResult.data.createTodo.text, 'This one was created with a mutation.');

const state = clonedeep(prev) as any;
state.todoList.todos.unshift(mResult.data.createTodo);
return state;
},
},
});
});

it('error handling in reducer functions', () => {
const oldError = console.error;
const errors: any[] = [];
Expand Down

0 comments on commit 945cb72

Please sign in to comment.