Skip to content

Cannot find module 'expect' from 'extend-expect.js' #34

Closed
@azdanov

Description

@azdanov

This only happens when I include import 'react-testing-library/extend-expect'. Otherwise react-testing-library works well. What might be the cause of this problem?

I am using latest create-react-app.

Error:

 FAIL  src/App.test.js
   Test suite failed to run

    Cannot find module 'expect' from 'extend-expect.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (node_modules/react-testing-library/dist/extend-expect.js:7:15)

Failing test:

it('should have a title', () => {
  const { getByText } = render(<App />);
  const text = 'Welcome to React';
  expect(getByText(text)).toBeInTheDOM();
});

Passing test:

it('should have a title', () => {
  const { getByText } = render(<App />);
  const text = 'Welcome to React';
  expect(getByText(text).innerHTML).toBe(text);
});

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