These functions are used to make it easier to write tests for GrAMPS data sources.
expectMockFields(resolver, fieldArray)
Creates Jest tests for each field in fieldArray
to ensure that the resolver
returns a mock value for it.
NOTE: This helper is intended for use with mock resolvers.
resolver
: a mock resolver for a given GraphQL typefieldArray
: an array of field names that should be mockedReturns a Jest test.
Assuming type PFX_MyType
with two fields, fieldOne
and fieldTwo
, which both have mock resolvers defined:
import resolvers from '../src/resolvers';describe('PFX_MyType', () => {const mockResolver = resolvers.mockResolvers.PFX_MyType();expectMockFields(mockResolver, ['fieldOne', 'fieldTwo']);});
expectMockList(resolver, fieldArray)
Creates Jest tests for each field in fieldArray
to ensure that the resolver
returns an instance of MockList
.
NOTE: This helper is intended for use with mock resolvers.
resolver
: a mock resolver for a given GraphQL typefieldArray
: an array of field names that should be mockedReturns an array of Jest tests.
Assuming type PFX_MyType
with two fields, fieldOne
and fieldTwo
, which both use MockList
to generate an array of mock data:
import resolvers from '../src/resolvers';describe('PFX_MyType', () => {const mockResolver = resolvers.mockResolvers.PFX_MyType();expectMockList(mockResolver, ['fieldOne', 'fieldTwo']);});
expectNullable(resolver, fieldArray)
Creates Jest tests for each field in fieldArray
to ensure that the resolver
returns null
if a value isn’t found for the given field.
NOTE: This helper is intended for use with field resolvers.
resolver
: a mock resolver for a given GraphQL typefieldArray
: an array of field names that should be mockedReturns an array of Jest tests.
Assuming type PFX_MyType
with one nullable field, fieldOne
:
import resolvers from '../src/resolvers';describe('PFX_MyType', () => {const resolver = resolvers.dataResolvers.PFX_MyType;expectNullable(resolver, ['fieldOne']);});