Skip to content

matcher.test is not a function - when using custom renderer. #538

Closed
@jaredmeakin

Description

@jaredmeakin
  • react-testing-library version: 9.2.0
  • react version: 16.9.0
  • node version: codesandbox
  • npm (or yarn) version: codesandbox

Relevant code or config:

Using the custom renderer provided in the setup example.

What you did:

Followed the docs for adding a custom renderer. The one in my project actually uses react-router and redux, but for simplicity the example pen doesn't have either of those. However, it still throws the same error.

What happened:

When using a custom renderer the methods returned by render are not useable—specifically matchers.

matcher.test is not a function

TypeError: matcher.test is not a function
    at matches (https://4njet.csb.app/node_modules/@testing-library/dom/dist/matches.js:39:20)
    at eval (https://4njet.csb.app/node_modules/@testing-library/dom/dist/query-helpers.js:41:82)
    at Array.filter (<anonymous>)
    at queryAllByAttribute (https://4njet.csb.app/node_modules/@testing-library/dom/dist/query-helpers.js:41:67)
    at queryAllByTestId (https://4njet.csb.app/node_modules/@testing-library/dom/dist/queries/test-id.js:12:73)
    at eval (https://4njet.csb.app/node_modules/@testing-library/dom/dist/query-helpers.js:73:17)
    at eval (https://4njet.csb.app/node_modules/@testing-library/dom/dist/query-helpers.js:86:105)
    at MutationObserverImpl.onMutation [as _callback] (https://4njet.csb.app/node_modules/@testing-library/dom/dist/wait-for-element.js:46:24)
    at notifyMutationObservers (https://4njet.csb.app/static/js/jsdom-4.0.0.min.js:1:2304010)
    at https://4njet.csb.app/static/js/jsdom-4.0.0.min.js:1:2303453

Reproduction:

https://codesandbox.io/s/react-testing-library-issue-4njet

Problem description:

Again, using a custom renderer the methods returned by render are throwing errors. Although my primary focus was the matchers I also observed issues when using debug from the destructured results render provides.

const { findAllByTestId, container, debug } = render(<Users />)

If you instead import the matcher methods from the testing-utils.js custom renderer directly this does NOT happen.

import { render, findAllByTestId } from "../testing-utils"

Suggested solution:

Not sure as to the cause, but I'm wondering if this is expected behavior? If so then maybe a simple update to the examples provided in the Setup section of the documentation would be sufficient. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions