question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'mockImplementationOnce' does not exist on type 'typeof StaticQuery'.

See original GitHub issue

Description

Trying to follow this doc.

Using "typescript": "^3.7.5" and "gatsby": "^2.18.12"

Am getting the following error:

Property 'mockImplementationOnce' does not exist on type 'typeof StaticQuery'.

Steps to reproduce

import { render } from '@testing-library/react';
import { axe } from 'jest-axe';
import React from 'react';
import { StaticQuery } from 'gatsby';

import Component from '.';

beforeEach(() => {
  StaticQuery.mockImplementationOnce(({ render }) =>
    render({
      site: {
        siteMetadata: {
          foo: "bar",
        },
      },
    })
  )
})

describe('Foo', () => {
  it('should render', async () => {
    const { container } = render(
      <Component />,
    );
    expect(container).toMatchSnapshot();

    const results = await axe(container);
    expect(results).toHaveNoViolations();
  });
});

Expected result

Should run tests and pass.

Actual result

$ jest --all --testNamePattern Foo
 FAIL  src/components/Foo/Foo.unit.spec.tsx
  ● Test suite failed to run

    TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
    src/components/Foo/Foo.unit.spec.tsx:9:15 - error TS2339: Property 'mockImplementationOnce' does not exist on type 'typeof StaticQuery'.

    9   StaticQuery.mockImplementationOnce(({ render }) =>
                    ~~~~~~~~~~~~~~~~~~~~~~
    src/components/Foo/Foo.unit.spec.tsx:9:41 - error TS7031: Binding element 'render' implicitly has an 'any' type.

    9   StaticQuery.mockImplementationOnce(({ render }) =>
                                              ~~~~~~


Test Suites: 1 failed, 1 of 7 total
Tests:       0 total
Snapshots:   0 total
Time:        61s

Environment

$ gatsby info --clipboard

  System:
    OS: Linux 5.4 Fedora 31 (Thirty One) 31 (Thirty One)
    CPU: (6) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.14.0 - ~/.nvm/versions/node/v12.14.0/bin/node
    Yarn: 1.21.1 - ~/.nvm/versions/node/v12.14.0/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v12.14.0/bin/npm
  Languages:
    Python: 3.7.4 - /home/vagrant/anaconda3/bin/python
  Browsers:
    Chrome: 79.0.3945.117
    Firefox: 72.0.1
  npmPackages:
    gatsby: ^2.18.12 => 2.19.10
    gatsby-image: ^2.2.34 => 2.2.39
    gatsby-plugin-apollo: ^3.0.1 => 3.0.1
    gatsby-plugin-emotion: ^4.1.21 => 4.1.21
    gatsby-plugin-google-tagmanager: ^2.1.25 => 2.1.25
    gatsby-plugin-manifest: ^2.2.31 => 2.2.40
    gatsby-plugin-react-axe: ^0.3.0 => 0.3.0
    gatsby-plugin-react-helmet: ^3.1.16 => 3.1.21
    gatsby-plugin-react-svg: ^3.0.0 => 3.0.0
    gatsby-plugin-sharp: ^2.3.5 => 2.4.4
    gatsby-plugin-sitemap: ^2.2.26 => 2.2.26
    gatsby-plugin-tsconfig-paths: ^1.0.1 => 1.0.2
    gatsby-plugin-tslint: ^0.0.2 => 0.0.2
    gatsby-plugin-typescript: ^2.1.26 => 2.1.26
    gatsby-source-filesystem: ^2.1.40 => 2.1.47
    gatsby-source-graphql: ^2.1.32 => 2.1.32
    gatsby-transformer-sharp: ^2.3.7 => 2.3.13
  npmGlobalPackages:
    gatsby-cli: 2.8.30

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
herecydevcommented, Mar 20, 2020

Sure I see what you’re saying now. However these docs aren’t meant to be referenced directly from github. They are build and displayed in the Gatsby docs site. So that markdown file is here:

https://www.gatsbyjs.org/docs/testing-components-with-graphql/

And you can see that the link (because it’s relative) is pointing to the correct place there.

0reactions
adam-hannacommented, Mar 20, 2020

Here: https://github.com/gatsbyjs/gatsby/blob/master/docs/docs/testing-components-with-graphql.md

First you should make sure you have read the unit testing guide…

Read more comments on GitHub >

github_iconTop Results From Across the Web

JestJS TypeScript: mockImplementation Does not Exist on Type
Im learning Jest with TypeScript and I'm facing the following type error: Property ' ...
Read more >
Testing a Typescript Gatsby app with Jest/Testing Library
Hi there, I have struggled with this for a few days now ... gives me this> Property 'mockImplementationOnce' does not exist on type...
Read more >
StaticQuery and Typescript - Medium
I was recently working on my portfolio site, and I wanted to easily pull in the site title with a graphQL query. After...
Read more >
How to use TypeScript and Jest mocks - Breno Calazans
TypeScript throws an error since it doesn't resolve mock files as Jest does. It expects useFooContext to have the type defined in its...
Read more >
Advanced GraphQL Usage In Gatsby Websites
As an example below, we have created a new type with the name of Aleem. It has hobbies which is an array of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found