title: How can i test my resolvers properly with jest?
body: <p>I'm trying to test my resolvers but i'd like to test each field of the response, here's the code to call the response:</p>
  
  <pre><code>interface Options {
    source: string;
    variableValues?: Maybe&lt;{ [key: string]: unknown | null }&gt;;
  }
  
  let schema: GraphQLSchema;
  
  const gCall = async ({
    source,
    variableValues,
  }: Options): Promise&lt;ExecutionResult&gt; =&gt; {
    if (!schema) {
      schema = await createSchema();
    }
    return graphql({
      schema,
      source,
      variableValues,
    });
  };
  
  export default gCall;
  </code></pre>
  
  <p>And that's the code to test the resolver:</p>
  
  <pre><code>let connection: Connection;
  const challengeMutation = `
  mutation CreateChallenge($data: CreateChallengeInput!) {
    createChallenge(data: $data) {
      id
      name
      category
      startDate
      endDate
      goal
      description
    }
  }
  `;
  
  describe('Create Challenge', () =&gt; {
    beforeAll(async () =&gt; {
      connection = await databaseTestConnection();
      await connection.createQueryBuilder().delete().from(Challenge).execute();
    });
  
    afterAll(async () =&gt; {
      await connection.createQueryBuilder().delete().from(Challenge).execute();
      await connection.close();
    });
  
    it('should create challenge', async () =&gt; {
      const challenge = {
        name: 'some awesome name',
        category: 'distância',
        startDate: new Date(2020, 7, 4).toISOString(),
        endDate: new Date(2020, 7, 5).toISOString(),
        goal: 5000,
        description: 'some excelent challenge description',
      };
  
      const response = await gCall({
        source: challengeMutation,
        variableValues: {
          data: challenge,
        },
      });
  
      expect(response).toMatchObject({
        data: {
          createChallenge: {
            name: challenge.name,
            category: challenge.category,
            startDate: challenge.startDate,
            endDate: challenge.endDate,
            goal: challenge.goal,
            description: challenge.description,
          },
        },
      });
    });
  });
  </code></pre>
  
  <p>What I'd like to do is test the fields separately, like this:</p>
  
  <pre><code>expect(response.data.createChallenge.name).toEqual(challenge.name);
  </code></pre>
  
  <p>But I'm getting the following error when I try to execute the above code:</p>
  
  <pre><code>Object is possibly 'null' or 'undefined'.
  </code></pre>
  
  <p>What can I do to solve this error and to make this test better?</p>