1 | import {
|
2 | ApolloQueryPipe,
|
3 | } from '../src';
|
4 |
|
5 | describe('ApolloQueryPipe', () => {
|
6 | let pipe: ApolloQueryPipe;
|
7 |
|
8 | beforeEach(() => {
|
9 | pipe = new ApolloQueryPipe();
|
10 | });
|
11 |
|
12 | it('should return nothing if name is empty', () => {
|
13 | expect(pipe.transform({ foo: 'bar' }, '')).toBe(undefined);
|
14 | });
|
15 |
|
16 | it('should return nothing if object is empty', () => {
|
17 | expect(pipe.transform({}, 'foo')).toBe(undefined);
|
18 | });
|
19 |
|
20 | it('should return nothing if object is missing', () => {
|
21 | expect(pipe.transform(undefined, 'foo')).toBe(undefined);
|
22 | });
|
23 |
|
24 | it('should return nothing if nothing has been found', () => {
|
25 | expect(pipe.transform({ foo: 'bar' }, 'baz')).toBe(undefined);
|
26 | });
|
27 |
|
28 | it('should be looking directly on object if the result comes from Apollo decorator', () => {
|
29 | const result = { foo: 'bar' };
|
30 |
|
31 | expect(pipe.transform(result, 'foo')).toEqual(result.foo);
|
32 | });
|
33 |
|
34 | it('should be looking inside data property iif the result comes fromf Angular2Apollo', () => {
|
35 | const result = {
|
36 | data: { foo: 'bar' },
|
37 | };
|
38 |
|
39 | expect(pipe.transform(result, 'foo')).toEqual(result.data.foo);
|
40 | });
|
41 | });
|