Skip to content

Cannot read property createContext of undefined with Jest #2339

@TrueWill

Description

@TrueWill

Describe the bug

Getting

TypeError: Cannot read property 'createContext' of undefined

on import { useQuery } from 'react-query' when running tests with Jest.

To Reproduce
Steps to reproduce the behavior:

We saw this when using a jest.config.js with the line moduleDirectories: ['node_modules', './'],
react-query v3.16.0

Expected behavior
Every other library works fine with Jest.

Desktop (please complete the following information):

  • OS: macOS Catalina
  • Browser: n/a - running tests with Jest v26.6.3 and Node v14.17.0

Additional context

A coworker figured out a fix based on blitz-js/blitz#1323 - changing the Jest config to moduleDirectories: ['node_modules', '<rootDir>'],. But this is the only library that's affected by it. According to the linked issue, this is caused by react-query having require("react") inside a folder named react.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions