Open totaltrash opened 7 months ago
Hey @totaltrash thanks for opening this issue! Testing isolated LiveComponents can be such a pain (usually I test them through their parent LiveView). But it would be great to be able to support this somehow.
Let me think about how we could expose this nicely. I'm not a huge fan of the idea of build_isolated
because it sounds specific to LiveView. But I wonder if there's a way to create an entry point (outside of visit
) that would allow us to use PhoenixTest like you're thinking.
Thanks @germsvel, yes it's a LiveView only thing, that's why I thought it might be considered out of scope. But, PhoenixTest has such a nice api, I can't use anything else now.
This might be a bit out of scope for phoenix_test, but thought I would ask!
I'd like to use phoenix_test to unit test live_components - unit test as in testing a live component that is not routable and not accessible using
visit
.The strategy I'm using is to define a live view in my test, something like this works well:
Just wondering if you would accept a PR to add
PhoenixTest.Live.build_isolated(conn, module)
that would do something similar toPhoenixTest.Live.build
, and optionally add aPhoenixTest.build_isolated(conn, module)
so it's available in the main test module? Then the test could look something like: