Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct typing issues with mocks in queryApiGateway test #587

Open
4 tasks
lomky opened this issue Dec 22, 2021 · 0 comments
Open
4 tasks

Correct typing issues with mocks in queryApiGateway test #587

lomky opened this issue Dec 22, 2021 · 0 comments
Labels
Engineering Technology and Development Track Type: Robustness Tickets to improve the application, invisibly
Milestone

Comments

@lomky
Copy link
Contributor

lomky commented Dec 22, 2021

Description

Issues with how the Jest mocks and the Typescript server interact means that the typing reports errors for every mocked function we are invoking. In particular, calls to fetch and fs return type errors as if they were the actual objects, instead of their mocked counterparts.

Discovered & spun out of #571

$ yarn typecheck
yarn run v1.22.17
$ tsc -p .
tests/utils/queryApiGateway.test.ts:50:11 - error TS2339: Property 'mockResolvedValue' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.

50     fetch.mockResolvedValue(new Response(JSON.stringify(mockedResponse)))
             ~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:54:21 - error TS2339: Property 'mockImplementation' does not exist on type '{ (path: number | PathLike, options?: { encoding?: null | undefined; flag?: string | undefined; } | null | undefined): Buffer; (path: number | PathLike, options: BufferEncoding | { ...; }): string; (path: number | PathLike, options?: BufferEncoding | ... 2 more ... | undefined): string | Buffer; }'.

54     fs.readFileSync.mockImplementation(() => {
                       ~~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:71:34 - error TS2554: Expected 1-2 arguments, but got 0.

71     const resp: Response = await fetch()
                                    ~~~~~~~

  node_modules/typescript/lib/lib.dom.d.ts:19624:24
    19624 declare function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
                                 ~~~~~~~~~~~~~~~~~~
    An argument for 'input' was not provided.

tests/utils/queryApiGateway.test.ts:97:11 - error TS2339: Property 'mockRejectedValue' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.

97     fetch.mockRejectedValue(new Error(networkErrorMessage))
             ~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:121:11 - error TS2339: Property 'mockResolvedValue' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.

121     fetch.mockResolvedValue(errorResponse403)
              ~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:145:11 - error TS2339: Property 'mockResolvedValue' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.

145     fetch.mockResolvedValue(new Response('not json'))
              ~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:168:21 - error TS2339: Property 'mockImplementation' does not exist on type '{ (path: number | PathLike, options?: { encoding?: null | undefined; flag?: string | undefined; } | null | undefined): Buffer; (path: number | PathLike, options: BufferEncoding | { ...; }): string; (path: number | PathLike, options?: BufferEncoding | ... 2 more ... | undefined): string | Buffer; }'.

168     fs.readFileSync.mockImplementation(() => {
                        ~~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:194:11 - error TS2339: Property 'mockResolvedValue' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.

194     fetch.mockResolvedValue(new Response(JSON.stringify(null)))
              ~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:252:11 - error TS2339: Property 'mockResolvedValue' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.

252     fetch.mockResolvedValue(new Response(JSON.stringify(longNullishResponse)))
              ~~~~~~~~~~~~~~~~~

tests/utils/queryApiGateway.test.ts:282:11 - error TS2339: Property 'mockResolvedValue' does not exist on type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.

282     fetch.mockResolvedValue(new Response(JSON.stringify(shortNullResponse)))
              ~~~~~~~~~~~~~~~~~


Found 10 errors.

Acceptance Criteria

  • All typing in queryApiGateway test is corrected
  • Remove //@ts-ignores & corresponding @typescript-eslint/ban-ts-comment comments from queryApiGateway test
  • Tests continue to function
  • App continues to function
@lomky lomky added Engineering Technology and Development Track Type: Robustness Tickets to improve the application, invisibly labels Dec 22, 2021
@lomky lomky added this to the Low Priority milestone Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engineering Technology and Development Track Type: Robustness Tickets to improve the application, invisibly
Projects
None yet
Development

No branches or pull requests

1 participant