graphql-modules icon indicating copy to clipboard operation
graphql-modules copied to clipboard

visitedTypes in the testkit does not include enums

Open BryBo617 opened this issue 4 years ago • 0 comments
trafficstars

While writing a test I discovered that enums are not listed in the visitedTypes. And cause testModule to fail.

My test:

it('Resolves query', async () => {
      const mockData = {
        contact: {
          email: '[email protected]',
          name: 'Bruce',
          phone: '913-555-1212',
        },
      };

      const mockResult = {
        _id: '1e9f12ca136a0d24b4a08821',
        ...mockData,
      };

      const app = testkit.testModule(myModule, {
        inheritTypeDefs: [module1, module2],
        providers: [
          {
            provide: myProvider,
            useValue: {
              getOne() {
                return {
                  ...mockData,
                };
              },
            },
          },
        ],
      });

      const result = await testkit.execute(app, {
        document: gql`
          query {
            getFromDatabase(filter: { _id: "1e9f12ca136a0d24b4a08821" }) {
              _id
              contact {
                email
                name
                phone
              }
            }
          }
        `,
      });

      expect(result.errors).toBeFalsy();
      expect(typeof result.data.getFromDatabase).toBe('object');
      expect(result.data.getFromDatabase).toEqual(mockResult);
    })

A workaround I have found is to include the Module with the enum types in both the inheritTypeDefs and the modules.

Environment:

  • OS: MAC
  • @graphql-modules/...:
  • NodeJS: 14.17.6

BryBo617 avatar Nov 03 '21 22:11 BryBo617