Skip to content
Merged
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
30 changes: 30 additions & 0 deletions tests/Angular2Apollo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,36 @@ describe('angular2Apollo', () => {
expect(result).toEqual('mutate');
});
});

describe('subscribe', () => {
it('should throw an error if method is missing', () => {
client.subscribe = undefined;

expect(() => {
angular2Apollo.subscribe({});
}).toThrowError('subscriptions');
});

it('should be called with the same options and return Observable', (done) => {
const options = {query: '', variables: {}};

spyOn(client, 'subscribe').and.returnValue(['subscription']);

const obs = angular2Apollo.subscribe(options);

expect(client.subscribe).toHaveBeenCalledWith(options);

obs.subscribe({
next(result) {
expect(result).toBe('subscription');
done();
},
error(error) {
done(new Error('should not be called'));
},
});
});
});
});

describe('defaultApolloClient', () => {
Expand Down
51 changes: 51 additions & 0 deletions tests/ApolloModule.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ApolloClient } from 'apollo-client';

import './_common';

import { ApolloModule, SelectPipe, Angular2Apollo } from '../src';
import { angularApolloClient } from '../src/Angular2Apollo';

describe('ApolloModule', () => {
let metadata: any = Reflect.getMetadata('annotations', ApolloModule)[0];

it('should contain SelectPipe in declarations', () => {
expect(include(metadata.declarations, SelectPipe)).toBe(true);
});

it('should export SelectPipe', () => {
expect(include(metadata.exports, SelectPipe)).toBe(true);
});

it('should not export Angular2Apollo', () => {
expect(include(metadata.exports, SelectPipe)).toBe(true);
});

it('should contain Angular2Apollo in providers', () => {
expect(include(metadata.exports, Angular2Apollo)).toBe(false);
});

it('should has withClient method', () => {
expect(ApolloModule.withClient).toBeDefined();
});

describe('withClient', () => {
const client = {} as ApolloClient;
const result = ApolloModule.withClient(client);

it('should contain ApolloModule as ngModule', () => {
expect(result.ngModule).toBe(ApolloModule);
});

it('should contain provider with useValue', () => {
expect(result.providers[0]['useValue']).toBe(client);
});

it('should contain provider that provide angularApolloClient', () => {
expect(result.providers[0]['provide']).toBe(angularApolloClient);
});
});
});

function include(source: any[], find: any): boolean {
return source.some(i => i === find);
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"typings.d.ts",
"src/index.ts",
"tests/Angular2Apollo.spec.ts",
"tests/SelectPipe.spec.ts"
"tests/SelectPipe.spec.ts",
"tests/ApolloModule.spec.ts"
]
}