Tag: jestjs
-
Testing graphql query in react error: TypeError: (0 , _client.gql) is not a function
0 I have this graphql query: export const LOAD_PLAYERS = gql` query GetPlayers { players { id firstname lastname shortname sex picture { url } country { code picture { url } } stats { rank age weight height points } } } `; I’m using it in this custom hook and it works just…
-
How to mock the external library graphql-request call using jest
0 I’m encountering difficulties while writing Jest unit tests for a module that interacts with graphql-request. Here’s the test import { jest } from ‘@jest/globals’; import { request } from ‘graphql-request’; import { logActivityPhoneCallScheduled, } from ‘./candidateService’; jest.mock(‘graphql-request’, () => { return { request: jest.fn(), }; }); beforeEach(() => { jest.clearAllMocks(); }); test(‘scheduled’, async ()…
-
How to solve graphql-rquest mockResolvedValue is not a function
0 In my project I’m updating to Node 18 and also converting from commonjs to esm. When I run the Jest tests I’m getting this error TypeError: request.mockResolvedValue is not a function In the following file but as you see the jest.mock()is on top of the scope as per documentation and also what I saw…
-
Jest – TypeGraphQL Invalid or Unexpected Token
0 I’m trying to create unit tests on my GraphQL API. This is the test file: import { graphql } from "graphql"; import { createSchema } from "../src/schema"; describe("BlacklistResolver", () => { it("fetches blacklist", async () => { const schema = await createSchema(); const query = ` query GetBlacklist($organisationId: String!) { getBlacklist(organisationId: $organisationId) } `;…
-
How to properly make mock throw an error in Jest?
176 I’m testing my GraphQL api using Jest. I’m using a separate test suit for each query/mutation I have 2 tests (each one in a separate test suit) where I mock one function (namely, Meteor’s callMethod) that is used in mutations. it(‘should throw error if email not found’, async () => { callMethod .mockReturnValue(new Error(‘User…