-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Update README to include testing example and helper #324
Conversation
Codecov ReportPatch and project coverage have no change.
Additional details and impacted files@@ Coverage Diff @@
## main #324 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 6 6
Lines 228 228
Branches 56 56
=========================================
Hits 228 228 ☔ View full report in Codecov by Sentry. |
@molefrog bump when you have a moment to review and thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @antgonzales. Sorry that it took me so long to look at your PR.
The README was missing the "Testing" section, so thank you for your help.
I'm a bit worried though that the example provided here is about testing React components with React testing library, rather than testing wouter apps. In my opinion, the example is a bit too specific, there are 4 unit tests included, that mostly check that the right route is rendered.
There is another discussion happening in a separate thread, where we discuss bringing back testing helpers that no longer present in the latest version. These helpers provided support for mocking the current location without modifying window.location
(primarily, because calling pushState
changes the history stack and since tests usually run in the same process this might result in unwanted side-effects). I see two options here: 1) wait for that discussion to be resolved and document those testing helpers 2) modify the current PR to simplify the example and focus more on how location can be mocked in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @molefrog for taking a look! I'm confused on the overall direction of your response.
Wouter is primarily a React and Preact routing tool and self-proclaimed alternative to React Router. If I'm going to use wouter, it's because I'm writing a React application, not a wouter application. It also looks like the wouter project makes heavy use of RTL in the tests, is the concern about Preact?
I settled on these examples using the examples from the existing README including:
What else should I be testing if I'm a consumer of wouter? I appreciate your feedback and time, let me know how I can better structure the tests to give consumers like me some examples and inspiration for putting together a test suite. |
Hi @antgonzales! I will try to provide an example to illustrate my point here. When you are writing unit tests, it is preferable to have each test as pure as possible, meaning that it's better to keep it only dedicated to the thing you are testing, not the dependencies that this feature is using. It's also better to have isolation, so that each case covers only one component of the system and not the whole system (otherwise, this becomes an integration test). This is why there are function mocks and test adapters (for example, when testing the rendering of a collection on a page, you can replace your fetching library with a mock one that returns data fixtures). In wouter, there are ways to mock the current location without relying on I think the example you have provided is definitely useful, it is just it is out of scope of the library and it mostly tests the routing features and not the features of the app itself. To provide an analogy, let's say you have a React app, and you have a unit test that checks that the component was updated when Here is what I suggest:
|
I have completely rewrote the README in v3 and included a chapter on testing using the latest API in 1f6964f The v2 branch is locked, so I have to close this issue. Thank you for your participation @antgonzales |
No description provided.