Testing portals
Hey,
I am currently trying to test a datepicker created with https://github.com/rnwonder/solid-date-picker with testing-libary.
However I am not quite sure how to select the actual picker. It seems to get rendered into a div with the id
portal-island
, which also shows up in my test, but without its contents.
What would be the general way to test this? I also tried to jsut use querySelector
but am not sure, how to get the correct container element to attach the querySelector to.
Thanks in advanceGitHub
GitHub - rnwonder/solid-date-picker: A simple and reusable Datepick...
A simple and reusable Datepicker component for SolidJS - GitHub - rnwonder/solid-date-picker: A simple and reusable Datepicker component for SolidJS
9 Replies
Do you have some example test code?
a very minimal example of the test would probably look something like this:
oh wait, I completely forgot to click the pickerinput...
that's probably the first issue here 😅
I would now be able to find one of the picker buttons by calling
screen.getByText(<some-day-number>)
- however looking for text by a number would probably be rather unreliable in the context of a picker.Hmm, why is that?
ah yeah sorry, some more context:
I am actually writing a small helper to make the interaction with the picker repeatable (a small layer of abstraction over our application UI).
The actual wrapper would look something like this:
So the day is configurable. Therefore it could technically happen, that a day is being used, that is not unique on the screen. But maybe I am overthinking this...
I see. Would it be overboard to
aria-label
them with the month?
Or maybe you could pick them out by style, if you want to avoid just going "I pick the first one because I know that's the right one"yeah, unfortunately I don't have access to the underlying day element, so I can't put an arial-label onto it (which would otherwise have been my first cause of action). Maybe picking by style might work - thanks for the suggestion 👍
oh wait, I am just seeing that these days might already have an aria-label I could select at 🤩
hooray for accessibility
yes, that works nicely, for reference, here's my updated code:
Thanks @hypersoar for thinkig this through with me 🙂
Happy to kinda help!