Skip to content

Commit

Permalink
test errors when express and koa are called with wrong args
Browse files Browse the repository at this point in the history
  • Loading branch information
helfer committed Jul 29, 2016
1 parent 11c6baf commit 5faab19
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/integrations/expressApollo.test.ts
Expand Up @@ -2,6 +2,8 @@ import * as express from 'express';
import * as bodyParser from 'body-parser';
import { apolloExpress, graphiqlExpress } from './expressApollo';
import testSuite, { Schema, CreateAppOptions } from './integrations.test';
import { expect } from 'chai';
import ApolloOptions from './apolloOptions';

function createApp(options: CreateAppOptions = {}) {
const app = express();
Expand All @@ -17,6 +19,17 @@ function createApp(options: CreateAppOptions = {}) {
return app;
}

describe('expressApollo', () => {
it('throws error if called without schema', function(){
expect(() => apolloExpress(undefined as ApolloOptions)).to.throw('Apollo Server requires options.');
});

it('throws an error if called with more than one argument', function(){
expect(() => (<any>apolloExpress)({}, 'x')).to.throw(
'Apollo Server expects exactly one argument, got 2');
});
});

describe('integration:Express', () => {
testSuite(createApp);
});
2 changes: 1 addition & 1 deletion src/integrations/expressApollo.ts
Expand Up @@ -26,7 +26,7 @@ export function apolloExpress(options: ApolloOptions | ExpressApolloOptionsFunct

if (arguments.length > 1) {
// TODO: test this
throw new Error(`Apollo Server expects exactly one argument, got ${arguments.length + 1}`);
throw new Error(`Apollo Server expects exactly one argument, got ${arguments.length}`);
}

return async (req: express.Request, res: express.Response, next) => {
Expand Down
13 changes: 13 additions & 0 deletions src/integrations/koaApollo.test.ts
Expand Up @@ -2,6 +2,8 @@ import * as koa from 'koa';
import * as koaRouter from 'koa-router';
import * as koaBody from 'koa-bodyparser';
import { apolloKoa, graphiqlKoa } from './koaApollo';
import ApolloOptions from './apolloOptions';
import { expect } from 'chai';

import testSuite, { Schema, CreateAppOptions } from './integrations.test';

Expand All @@ -27,6 +29,17 @@ function destroyApp(app) {
app.close();
}

describe('expressApollo', () => {
it('throws error if called without schema', function(){
expect(() => apolloKoa(undefined as ApolloOptions)).to.throw('Apollo Server requires options.');
});

it('throws an error if called with more than one argument', function(){
expect(() => (<any>apolloKoa)({}, 'x')).to.throw(
'Apollo Server expects exactly one argument, got 2');
});
});

describe('integration:Koa', () => {
testSuite(createApp, destroyApp);
});
2 changes: 1 addition & 1 deletion src/integrations/koaApollo.ts
Expand Up @@ -18,7 +18,7 @@ export function apolloKoa(options: ApolloOptions | KoaApolloOptionsFunction): Ko
}

if (arguments.length > 1) {
throw new Error(`Apollo Server expects exactly one argument, got ${arguments.length + 1}`);
throw new Error(`Apollo Server expects exactly one argument, got ${arguments.length}`);
}

return async (ctx, next) => {
Expand Down

0 comments on commit 5faab19

Please sign in to comment.