Adding SSR test for form fields.#9264
Conversation
sophiebits
left a comment
There was a problem hiding this comment.
Nice! These didn't feel too clumsy to me.
| <input value="foo" defaultValue="bar" readOnly={true} />, | ||
| 1, | ||
| ); | ||
| expect(e.value).toBe('foo'); |
There was a problem hiding this comment.
Do you want to check e.getAttribute('value') too?
There was a problem hiding this comment.
Good call. I added those checks in a734aec. Thanks!
| itRenders( | ||
| 'an input with a value and no onChange/readOnly', | ||
| async render => { | ||
| // this configuration should raise a dev warning that value without |
There was a problem hiding this comment.
I suppose it's not clear to me whether we should try to keep all the warnings in sync between the renderers. It seems not-super-valuable if you always revive on the client side, though I suppose if we want to support server-only rendering then we should have all the warnings there too. In any event, this seems good for now.
There was a problem hiding this comment.
I agree; I'm genuinely not certain if it's a good idea to have in SSR or not. If not, we can just change these tests pretty easily, though.
|
Thanks, merged! 🎉🎉🎉 |
|
🎉 :D |
This is the last (🎉😢) of my planned SSR unit test PRs (following on #9055, #9089, #9106, #9221, and #9257). It tests form fields:
<input type=text>,<input type=checkbox>,<textarea>, and<select>.The first set of tests makes sure that the server renderer correctly maps React properties for each of those fields to correct DOM properties (or for
textarea, to inner text). It also makes sure that the renderer warns when a value is set without onChange or readOnly.The latter tests attempt to make sure that form fields that have been server rendered work correctly with user interaction, whether they are controlled or uncontrolled and whether the user interaction happens before client render or after.
I also deleted a duplicative unrelated test that @spicyj mentioned in a review comment on #9257.
This set of tests are more verbose and a little more complex than some of the others; I welcome any feedback to make them more readable. Thanks!