Commit 00c4ae6a authored by Robert Knight's avatar Robert Knight

Add a test for search being canceled before failing

Add a test for what happens if a search is canceled and the in-flight
request ends up failing.
parent c2d86ec8
...@@ -6,6 +6,10 @@ function awaitEvent(emitter, event) { ...@@ -6,6 +6,10 @@ function awaitEvent(emitter, event) {
}); });
} }
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
describe('SearchClient', () => { describe('SearchClient', () => {
const RESULTS = [ const RESULTS = [
{ id: 'one' }, { id: 'one' },
...@@ -144,6 +148,19 @@ describe('SearchClient', () => { ...@@ -144,6 +148,19 @@ describe('SearchClient', () => {
}); });
}); });
it('does not emit "error" event if search is canceled before it fails', async () => {
fakeSearchFn = () => Promise.reject(new Error('search failed'));
const client = new SearchClient(fakeSearchFn);
const onError = sinon.stub();
client.on('error', onError);
client.get({ uri: 'http://example.com' });
client.cancel();
await delay(0);
assert.notCalled(onError);
});
context('`maxResults` option present', () => { context('`maxResults` option present', () => {
it('emits error if results size exceeds `maxResults`', () => { it('emits error if results size exceeds `maxResults`', () => {
const client = new SearchClient(fakeSearchFn, { maxResults: 2 }); const client = new SearchClient(fakeSearchFn, { maxResults: 2 });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment