Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use done.fail(e) instead of done(e) for forced failures #2199

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/apollo-client/src/__tests__/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ describe('client', () => {
if (e === expectedError) {
done();
} else {
done(e);
done.fail(e);
}
};
process.removeListener('uncaughtException', oldHandler);
Expand Down Expand Up @@ -656,7 +656,7 @@ describe('client', () => {
if (e === expectedError) {
done();
} else {
done(e);
done.fail(e);
}
};
process.removeListener('uncaughtException', oldHandler);
Expand Down Expand Up @@ -685,7 +685,7 @@ describe('client', () => {
const handle = client.watchQuery({ query });
handle.subscribe({
next() {
done(new Error('did not expect next to be called'));
done.fail(new Error('did not expect next to be called'));
},
error() {
throw expectedError;
Expand Down Expand Up @@ -1242,11 +1242,11 @@ describe('client', () => {
done();
})
.catch(err => {
done(err);
done.fail(err);
});
},
error(err) {
done(err);
done.fail(err);
},
});
});
Expand Down Expand Up @@ -1649,7 +1649,9 @@ describe('client', () => {
}
if (handleCount === 2) {
handleCalled = true;
done(new Error('Handle should never be called on standby query'));
done.fail(
new Error('Handle should never be called on standby query'),
);
}
});
});
Expand Down Expand Up @@ -1845,7 +1847,7 @@ describe('client', () => {
client
.mutate({ mutation })
.then(_ => {
done(new Error('Returned a result when it should not have.'));
done.fail(new Error('Returned a result when it should not have.'));
})
.catch((error: ApolloError) => {
expect(error.networkError).toBeDefined();
Expand Down Expand Up @@ -1882,7 +1884,7 @@ describe('client', () => {
client
.mutate({ mutation })
.then(_ => {
done(new Error('Returned a result when it should not have.'));
done.fail(new Error('Returned a result when it should not have.'));
})
.catch((error: ApolloError) => {
expect(error.graphQLErrors).toBeDefined();
Expand Down Expand Up @@ -2009,7 +2011,7 @@ describe('client', () => {
).toBe(1);
mutatePromise
.then(_ => {
done(new Error('Returned a result when it should not have.'));
done.fail(new Error('Returned a result when it should not have.'));
})
.catch((_: ApolloError) => {
expect(
Expand Down
40 changes: 26 additions & 14 deletions packages/apollo-client/src/__tests__/fetchMore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,11 @@ describe('fetchMore on an observable query', () => {
done();
break;
default:
done(new Error('`next` called too many times'));
done.fail(new Error('`next` called too many times'));
}
},
error: error => done(error),
complete: () => done(new Error('Should not have completed')),
error: error => done.fail(error),
complete: () => done.fail(new Error('Should not have completed')),
});
});

Expand Down Expand Up @@ -414,7 +414,9 @@ describe('fetchMore on an observable query', () => {
expect((data as any).entry.comments.length).toBe(10);
break;
default:
done(new Error('`next` called when it wasn’t supposed to be.'));
done.fail(
new Error('`next` called when it wasn’t supposed to be.'),
);
}
},
error: error => {
Expand All @@ -425,14 +427,18 @@ describe('fetchMore on an observable query', () => {
done();
break;
default:
done(new Error('`error` called when it wasn’t supposed to be.'));
done.fail(
new Error('`error` called when it wasn’t supposed to be.'),
);
}
} catch (error) {
done(error);
done.fail(error);
}
},
complete: () =>
done(new Error('`complete` called when it wasn’t supposed to be.')),
done.fail(
new Error('`complete` called when it wasn’t supposed to be.'),
),
});
});
});
Expand Down Expand Up @@ -612,11 +618,11 @@ describe('fetchMore on an observable query with connection', () => {
done();
break;
default:
done(new Error('`next` called too many times'));
done.fail(new Error('`next` called too many times'));
}
},
error: error => done(error),
complete: () => done(new Error('Should not have completed')),
error: error => done.fail(error),
complete: () => done.fail(new Error('Should not have completed')),
});
});

Expand Down Expand Up @@ -665,7 +671,9 @@ describe('fetchMore on an observable query with connection', () => {
expect((data as any).entry.comments.length).toBe(10);
break;
default:
done(new Error('`next` called when it wasn’t supposed to be.'));
done.fail(
new Error('`next` called when it wasn’t supposed to be.'),
);
}
},
error: error => {
Expand All @@ -676,14 +684,18 @@ describe('fetchMore on an observable query with connection', () => {
done();
break;
default:
done(new Error('`error` called when it wasn’t supposed to be.'));
done.fail(
new Error('`error` called when it wasn’t supposed to be.'),
);
}
} catch (error) {
done(error);
done.fail(error);
}
},
complete: () =>
done(new Error('`complete` called when it wasn’t supposed to be.')),
done.fail(
new Error('`complete` called when it wasn’t supposed to be.'),
),
});
});
});
20 changes: 10 additions & 10 deletions packages/apollo-client/src/__tests__/mutationResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ describe('mutation results', () => {
},
})
.then(
() => done(new Error('Mutation should have failed')),
() => done.fail(new Error('Mutation should have failed')),
() =>
client.mutate({
mutation,
Expand All @@ -570,10 +570,10 @@ describe('mutation results', () => {
}),
)
.then(
() => done(new Error('Mutation should have failed')),
() => done.fail(new Error('Mutation should have failed')),
() => obsHandle.refetch(),
)
.then(() => done(), done);
.then(() => done(), done.fail);
},
});
});
Expand Down Expand Up @@ -690,7 +690,7 @@ describe('mutation results', () => {

const firstSubs = watchedQuery.subscribe({
next: () => null,
error: done,
error: done.fail,
});

// Cancel the query right away!
Expand Down Expand Up @@ -800,7 +800,7 @@ describe('mutation results', () => {
});
done();
})
.catch(done);
.catch(done.fail);
});

it('allows mutations with default values', done => {
Expand Down Expand Up @@ -878,7 +878,7 @@ describe('mutation results', () => {
});
done();
})
.catch(done);
.catch(done.fail);
});

it('will pass null to the network interface when provided', done => {
Expand Down Expand Up @@ -957,7 +957,7 @@ describe('mutation results', () => {
});
done();
})
.catch(done);
.catch(done.fail);
});

describe('store transaction updater', () => {
Expand Down Expand Up @@ -1192,7 +1192,7 @@ describe('mutation results', () => {
},
})
.then(
() => done(new Error('Mutation should have failed')),
() => done.fail(new Error('Mutation should have failed')),
() =>
client.mutate({
mutation,
Expand Down Expand Up @@ -1228,10 +1228,10 @@ describe('mutation results', () => {
}),
)
.then(
() => done(new Error('Mutation should have failed')),
() => done.fail(new Error('Mutation should have failed')),
() => obsHandle.refetch(),
)
.then(() => done(), done);
.then(() => done(), done.fail);
},
});
});
Expand Down
16 changes: 8 additions & 8 deletions packages/apollo-client/src/__tests__/optimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,10 +1175,10 @@ describe('optimistic mutation results', () => {
done();
break;
default:
done(new Error('Next should not have been called again.'));
done.fail(new Error('Next should not have been called again.'));
}
},
error: error => done(error),
error: error => done.fail(error),
});

function twoMutations() {
Expand All @@ -1188,15 +1188,15 @@ describe('optimistic mutation results', () => {
optimisticResponse: customOptimisticResponse1,
updateQueries,
})
.catch(error => done(error));
.catch(error => done.fail(error));

client
.mutate({
mutation,
optimisticResponse: customOptimisticResponse2,
updateQueries,
})
.catch(error => done(error));
.catch(error => done.fail(error));
}
});
});
Expand Down Expand Up @@ -1681,10 +1681,10 @@ describe('optimistic mutation results', () => {
done();
break;
default:
done(new Error('Next should not have been called again.'));
done.fail(new Error('Next should not have been called again.'));
}
},
error: error => done(error),
error: error => done.fail(error),
});

function twoMutations() {
Expand All @@ -1694,15 +1694,15 @@ describe('optimistic mutation results', () => {
optimisticResponse: customOptimisticResponse1,
update,
})
.catch(error => done(error));
.catch(error => done.fail(error));

client
.mutate({
mutation,
optimisticResponse: customOptimisticResponse2,
update,
})
.catch(error => done(error));
.catch(error => done.fail(error));
}
});
});
Expand Down
10 changes: 5 additions & 5 deletions packages/apollo-client/src/core/__tests__/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ describe('ObservableQuery', () => {
jest.runTimersToTime(100);
done();
} else if (handleCount === 2) {
done(new Error('Should not get more than one result'));
done.fail(new Error('Should not get more than one result'));
}
});

Expand Down Expand Up @@ -604,7 +604,7 @@ describe('ObservableQuery', () => {
expect(result2.data).toEqual(dataTwo);
try {
(result2.data as any).stuff = 'awful';
done(
done.fail(
new Error(
'results from setVariables should be frozen in development mode',
),
Expand Down Expand Up @@ -993,7 +993,7 @@ describe('ObservableQuery', () => {
stale: false,
});
} catch (e) {
done(e);
done.fail(e);
}

if (count === 1) {
Expand All @@ -1003,7 +1003,7 @@ describe('ObservableQuery', () => {
setTimeout(done, 5);
}
if (count > 3) {
done(new Error('Observable.next called too many times'));
done.fail(new Error('Observable.next called too many times'));
}
});
});
Expand Down Expand Up @@ -1292,7 +1292,7 @@ describe('ObservableQuery', () => {
} else if (handleCount === 2) {
// oops! we are polling for data, this should not happen.
startedPolling = true;
done(new Error('should not start polling, already stopped'));
done.fail(new Error('should not start polling, already stopped'));
}
});

Expand Down
Loading