Do you think having unit tests in the usage examples would be useful? #1438
Replies: 2 comments 2 replies
-
Nothing currently stops you from doing unit testing using memory history ( The problems start when you try to test components (instead of the actual pages) that use parts of TanStack Router. This is because the Router does a lot of runtime validation and as such you need to have it actually booted-up and running. Since all the hooks consumed by TanStack Router are built upon But, again, this doesn't prevent you from doing so. It just means that you aren't able to test components in a traditional sense, you need to consider it from page point-of-view. All that said, we're happy to accept PRs of good examples. If you've got a good example of testing apps using TSR, pull up a PR, community contributions are welcome. |
Beta Was this translation helpful? Give feedback.
-
I think it would be helpful to have some good solutions for unit testing because it's not easy. My current approach is creating test routes with test RouterProvider for every single unit test, but it has a few problems:
It seems like there should be a better way to unit test routes but I haven't been able to come up with anything. Maybe loading the entire application route tree in each test and adding an additional test route to that would solve issue 2 that I mentioned. I currently use playwright e2e tests to verify some of the router logic, but that's hitting a real server. It's much slower and less reliable than unit tests so I would prefer to do as much router coverage as possible with unit tests. |
Beta Was this translation helpful? Give feedback.
-
Tansktack Router is brilliant, but it is not obvious how to create unit tests for the routing functionality of an app built upon it. Perhaps having some examples of unit tests in the examples would be helpful to developers who are starting to use the library.
33 votes ·
Beta Was this translation helpful? Give feedback.
All reactions