Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: v7 - unable to import react-router/testing #12185

Closed
ondrejsevcik opened this issue Oct 24, 2024 · 3 comments · Fixed by #12186
Closed

[Bug]: v7 - unable to import react-router/testing #12185

ondrejsevcik opened this issue Oct 24, 2024 · 3 comments · Fixed by #12186
Labels

Comments

@ondrejsevcik
Copy link

What version of React Router are you using?

7.0.0-pre.2

Steps to Reproduce

  1. Install react-router package in version 7.0.0-pre.2.
  2. Try to import import { createStub } from 'react-router/testing'
  3. It will fail, since there is no testing export in the package.json defined

Expected Behavior

According to the dev testing documentation, it should be possible to import from this package.

Actual Behavior

The build fails with

error TS2307: Cannot find module 'react-router/testing' or its corresponding type declarations.
import { createStub } from 'react-router/testing'
@brophdawg11
Copy link
Contributor

I think this is just a docs issue - try import { createRoutesStub } from "react-router"?

@ondrejsevcik
Copy link
Author

ondrejsevcik commented Oct 25, 2024

Using the import { createRoutesStub } from "react-router" works 👍🏼 , but then I run into another issue.

According to the docs, I should also use route import. But when I do according to the docs, I run into TS issues.

Docs

  const Stub = createStub([
    route("/login", {
      Component: LoginForm,
    })

whereas real types for route expect 2nd argument to be file path.

CleanShot 2024-10-25 at 11 09 01@2x

@brophdawg11
Copy link
Contributor

brophdawg11 commented Oct 25, 2024

ah ok yeah those route helpers don't make sense for testing (at least at the moment) - I'll update that in the docs too

const Stub = createStub([
  { 
    path:"/login",
    Component: LoginForm,
  }
]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants