|
1 | | -import { makeMockContext } from './makeMockContext' |
| 1 | +import { makeCustomContext } from './makeCustomContext' |
2 | 2 | import { QueryDefinition } from '../types/Query' |
3 | 3 | import { bigIntLiteral } from '@babel/types' |
4 | 4 |
|
5 | | -describe('makeMockContext', () => { |
6 | | - it('Should throw if requested resource is not mocked', () => { |
7 | | - const context = makeMockContext({}) |
| 5 | +describe('makeCustomContext', () => { |
| 6 | + it('Should throw if requested custom resource is not provided', () => { |
| 7 | + const context = makeCustomContext({}) |
8 | 8 | expect(context.fetch({ resource: 'test' })).rejects.toBeTruthy() |
9 | 9 | }) |
10 | 10 | it('Should return empty object on miss if failOnMiss=false', async () => { |
11 | | - const context = makeMockContext({}, { failOnMiss: false }) |
| 11 | + const context = makeCustomContext({}, { failOnMiss: false }) |
12 | 12 | expect(await context.fetch({ resource: 'test' })).toEqual({}) |
13 | 13 | }) |
14 | | - it('Should return mocked resources', async () => { |
15 | | - const mockData = { |
| 14 | + it('Should return custom resources', async () => { |
| 15 | + const customData = { |
16 | 16 | test: { value: 'something' }, |
17 | 17 | user: { id: 42 }, |
18 | 18 | } |
19 | | - const context = makeMockContext(mockData) |
20 | | - expect(await context.fetch({ resource: 'test' })).toEqual(mockData.test) |
21 | | - expect(await context.fetch({ resource: 'user' })).toEqual(mockData.user) |
| 19 | + const context = makeCustomContext(customData) |
| 20 | + expect(await context.fetch({ resource: 'test' })).toEqual( |
| 21 | + customData.test |
| 22 | + ) |
| 23 | + expect(await context.fetch({ resource: 'user' })).toEqual( |
| 24 | + customData.user |
| 25 | + ) |
22 | 26 | }) |
23 | | - it('Should resolve mocked resource with function', async () => { |
24 | | - const mockData = { |
| 27 | + it('Should resolve custom resource with function', async () => { |
| 28 | + const customData = { |
25 | 29 | test: { value: 'something' }, |
26 | 30 | user: { id: 42 }, |
27 | 31 | } |
28 | | - const context = makeMockContext(mockData) |
29 | | - expect(await context.fetch({ resource: 'test' })).toEqual(mockData.test) |
30 | | - expect(await context.fetch({ resource: 'user' })).toEqual(mockData.user) |
| 32 | + const context = makeCustomContext(customData) |
| 33 | + expect(await context.fetch({ resource: 'test' })).toEqual( |
| 34 | + customData.test |
| 35 | + ) |
| 36 | + expect(await context.fetch({ resource: 'user' })).toEqual( |
| 37 | + customData.user |
| 38 | + ) |
31 | 39 | }) |
32 | 40 | it('Should throw if resolver returns undefined', async () => { |
33 | | - const mockData = { |
| 41 | + const customData = { |
34 | 42 | test: () => undefined, |
35 | 43 | } |
36 | | - const context = makeMockContext(mockData) |
| 44 | + const context = makeCustomContext(customData) |
37 | 45 | expect(context.fetch({ resource: 'test' })).rejects.toBeTruthy() |
38 | 46 | }) |
39 | 47 | it('Should not throw if resolver returns undefined with failOnMiss=false', async () => { |
40 | | - const mockData = { |
| 48 | + const customData = { |
41 | 49 | test: () => undefined, |
42 | 50 | } |
43 | | - const context = makeMockContext(mockData, { failOnMiss: false }) |
| 51 | + const context = makeCustomContext(customData, { failOnMiss: false }) |
44 | 52 | expect(context.fetch({ resource: 'test' })).resolves.toEqual({}) |
45 | 53 | }) |
46 | | - it('Should throw if mock is something crazy like a bigint', async () => { |
47 | | - const mockData = { |
| 54 | + it('Should throw if custom data is something crazy like a bigint', async () => { |
| 55 | + const customData = { |
48 | 56 | test: null as any, |
49 | 57 | } |
50 | | - const context = makeMockContext(mockData, { failOnMiss: false }) |
| 58 | + const context = makeCustomContext(customData, { failOnMiss: false }) |
51 | 59 | expect(context.fetch({ resource: 'test' })).resolves.toEqual({}) |
52 | 60 | }) |
53 | 61 | }) |
0 commit comments