robrichard / graphql-fields

Turns GraphQLResolveInfo into a map of the requested fields
MIT License
350 stars 30 forks source link

How to incorporate this library when unit testing components #49

Open jonnydungeons opened 2 years ago

jonnydungeons commented 2 years ago

I have a problem. Currently my company is incorporating this at the top level of a component during unit tests like so: `... import { GraphQLFieldsReturnType } from '../../../type-defs';

jest.mock('graphql-fields', () => ({ __esModule: true, default: (arg: unknown): GraphQLFieldsReturnType => { if (!arg) { return null; } return { savings: 'ALL', someContent: { modules: 'Array', dynamicContent: 'Object' }, referralLink: 'http://xyz.com', }; }, })); describe('getPlansV1 resolvers', () => { ...`

My problem is that this makes testing very rigid and because it is at top level outside of component testing I would like to also incorporate other unit tests with various returns. How could I do that?

In the above code example we are bootstrapping your library to return nothing but I would also like to bootstrap it with return data that executes a happy path but it fails if I try to relocate this code from where it currently is to inside of a describe.

Keeping up the fight.