Skip to content

v14 "hides" expo-router's extended jest matchers like toHavePathname #1924

Description

@kovbe21

Describe the bug

On expo and expo-router v55 (v56 also), testing library v14.

Expo router has extended jest matchers like toHavePathname. See docs: https://docs.expo.dev/router/reference/testing/#jest-matchers

After updating to v14, these matchers are no longer working, throwing TypeError.

Example reproduction repository: https://github.com/kovbe21/jest-reproductions (path-name.test.tsx)

Not sure whether an expo-router, or react-native-testing-library bug, will report it to expo as well, but the problem has been introduced with react-native-testing-library v14. On v13 it was working fine.

Expected behavior

When using expo-router's extended matchers, it should not throw error, and match the expected pathname.

Steps to Reproduce

Example reproduction repository: https://github.com/kovbe21/jest-reproductions

  • Run test named path-name.test.tsx

OR:

it('expo-router test should pass', async () => {
  const MockComponent = jest.fn(() => <View />);

  await renderRouter(
    {
      index: MockComponent,
      'directory/a': MockComponent,
      '(group)/b': MockComponent,
    },
    {
      initialUrl: '/directory/a',
    }
  );

  // TypeError: screen.getPathname is not a function
  expect(screen).toHavePathname('/directory/a');
});

Versions

npmPackages:
@testing-library/react-native: ^14.0.1 => 14.0.1
react: 19.2.0 => 19.2.0
react-native: 0.83.6 => 0.83.6
test-renderer: ^1.2.0 => 1.2.0

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