-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[layout tests] Function for rendering a single node and getting the resulting web_sys::Element #3579
[layout tests] Function for rendering a single node and getting the resulting web_sys::Element #3579
Conversation
Benchmark - coreYew Master
Pull Request
|
Visit the preview URL for this PR (updated for commit 6f7d0af): https://yew-rs-api--pr3579-render-single-compon-9x572jwg.web.app (expires Thu, 11 Jan 2024 13:16:07 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
8105e41
to
aa5f8a0
Compare
Benchmark - SSRYew Master
Pull Request
|
aa5f8a0
to
6f7d0af
Compare
Size Comparison
✅ None of the examples has changed their size significantly. |
The clippy complaints don't result from the changes made in this PR. |
This is because the initial render is delayed and no longer happens immediately. The renderer now renders right before the event loop is returned to the browser so render only happens once regardless of the number of state updates that triggers a render. You should yield to the browser / renderer with |
This works! I do wonder if there might not be a way to support handling the events immediately in I guess I can close this PR since there's an easier workaround. |
I think the better way might be to make the tests to search for its desired state until it reaches what its desired state (queries and assertions are awaited), like react-testing-library. A couple years ago, I made an experimental attempt to write a wrapper for See: https://github.com/futursolo/reality-rs/blob/master/crates/reality-yew/src/lib.rs#L12 |
I would like to avoid using cypress for smaller components or very simple interactions. If Cypress component testing would work for Yew, then that would of course be perfect but using end-to-end tests for everything seems a bit nuked.
Agreed. But if this (naive) approach already works in a lot of cases then I'll be happy with that until something better comes along 😁 |
Description
Following up from #3578 but important bits are reexplained here.
Pulls in code from #3463.
This PR adds a function with which a single component is rendered once and the resulting web_sys::Element is returned. This allows then querying the resulting element to run verification on only a subset of the resulting HTML code instead of all of it. This means that tests can be more fine-tuned resulting in less breakage through things such as style changes.
Limitations
Interactions with the DOM aren't possible with this since the scheduler doesn't run again. I would be interested in suggestions on how to implement that, so that users can get an experience similar to the JavaScript "DOM Testing Library" where the following is possible:
A crate called frontest was able to achieve a similar result with Yew 0.19 the following way:
However, using Yew 0.21's
Renderer::<Wrapper>::with_root_and_props(...).render()
does not lead to the same results - the div created div is simply empty. I assume that the scheduler isn't started but I don't know enough about the internals of Yew.Being able to offer this functionality would make testing Yew apps significantly easier.
Checklist