Skip to content

Commit

Permalink
test(handler): should bubble onNext errors
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Dec 31, 2021
1 parent 9843e51 commit 3bb5aaf
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/__tests__/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import fetch from 'node-fetch';
import express from 'express';
import Fastify from 'fastify';

// just does nothing
function noop(): void {
/**/
}

it('should only accept valid accept headers', async () => {
const { request } = await startTServer();

Expand Down Expand Up @@ -205,6 +210,48 @@ describe('single connection mode', () => {

es.close();
});

it('should bubble errors thrown in onNext to the handler', async (done) => {
const onNextErr = new Error('Woops!');

const handler = createHandler({
schema,
onNext: () => {
throw onNextErr;
},
});

const [, url, dispose] = await startDisposableServer(
http.createServer(async (req, res) => {
try {
await handler(req, res);
} catch (err) {
expect(err).toBe(onNextErr);

await dispose();
done();
}
}),
);

const client = createClient({
singleConnection: true,
url,
fetchFn: fetch,
retryAttempts: 0,
});

client.subscribe(
{
query: '{ getValue }',
},
{
next: noop,
error: noop,
complete: noop,
},
);
});
});

describe('distinct connections mode', () => {
Expand Down Expand Up @@ -315,6 +362,47 @@ describe('distinct connections mode', () => {

await waitForComplete();
});

it('should bubble errors thrown in onNext to the handler', async (done) => {
const onNextErr = new Error('Woops!');

const handler = createHandler({
schema,
onNext: () => {
throw onNextErr;
},
});

const [, url, dispose] = await startDisposableServer(
http.createServer(async (req, res) => {
try {
await handler(req, res);
} catch (err) {
expect(err).toBe(onNextErr);

await dispose();
done();
}
}),
);

const client = createClient({
url,
fetchFn: fetch,
retryAttempts: 0,
});

client.subscribe(
{
query: '{ getValue }',
},
{
next: noop,
error: noop,
complete: noop,
},
);
});
});

describe('express', () => {
Expand Down

0 comments on commit 3bb5aaf

Please sign in to comment.