germsvel / phoenix_test

PhoenixTest provides a unified way of writing feature tests -- regardless of whether you're testing LiveView pages or static (non-LiveView) pages.
https://hex.pm/packages/phoenix_test
MIT License
176 stars 23 forks source link

Test error after upgrading to 0.3.2 : `(ArgumentError) no push or navigation command found within JS commands` #122

Closed joshk closed 4 weeks ago

joshk commented 1 month ago

After upgrade phoenix_test to 0.3.2 I have two tests failing for the same reason.

1) test new create with JITP (NervesHubWeb.Live.Org.CertificateAuthoritiesTest)
     test/nerves_hub_web/live/org/certificate_authorities_test.exs:120
     ** (ArgumentError) no push or navigation command found within JS commands: [["dispatch",{"event":"ca:new:jitp"}]]
     code: |> check("Enable Just In Time Provisioning")
     stacktrace:
       (phoenix_live_view 0.20.17) lib/phoenix_live_view/test/live_view_test.ex:1102: Phoenix.LiveViewTest.call/2
       (phoenix_test 0.3.2) lib/phoenix_test/live.ex:138: PhoenixTest.Live.check/2
       test/nerves_hub_web/live/org/certificate_authorities_test.exs:146: (test)

This is the full test here: https://github.com/nerves-hub/nerves_hub_web/blob/main/test/nerves_hub_web/live/org/certificate_authorities_test.exs#L119-L166

And here is the full html: https://github.com/nerves-hub/nerves_hub_web/blob/main/lib/nerves_hub_web/live/org/certificate_authority_templates/new_ca_template.html.heex (the checkbox in question: https://github.com/nerves-hub/nerves_hub_web/blob/main/lib/nerves_hub_web/live/org/certificate_authority_templates/new_ca_template.html.heex#L73)

Am I doing something wrong?

germsvel commented 1 month ago

@joshk thanks for opening the issue. I'm looking at the code you shared, and I can't really see how things would've changed in 0.3.2. I'll try to take a deeper look at the changes we made to see if anything comes up.

In the meantime, is there a way you could try to reproduce the error in a simpler phoenix app? something I can pull down and play around with?

Another question: do you know if you also updated LiveView when you upgraded phoenix test 0.3.2? The error you're seeing looks like something that would come out of LiveView or LiveViewTest, which makes me think something else might've changed.

germsvel commented 1 month ago

@joshk I'm going to close this for now since it seems like there's no way for me to reproduce this.

If you find the time to create a simple Phoenix app that reproduces the error, I'd be happy to reopen this!

joshk commented 1 month ago

Totally understand. We are stuck on 0.3.1 for now, until I can show the issue in a small app.

joshk commented 1 month ago

Another question: do you know if you also updated LiveView when you upgraded phoenix test 0.3.2? The error you're seeing looks like something that would come out of LiveView or LiveViewTest, which makes me think something else might've changed.

I forgot to reply and say that no, we haven't changed LiveView versions, this is isolated to only PhoenixTest.

germsvel commented 1 month ago

I'll reopen this in case you get time to create a simple app to try to reproduce what's going on there.

germsvel commented 4 weeks ago

@joshk while solving another issue, I figured out why your test started breaking after 0.3.2

In 0.3.2, we introduced the ability for checkboxes to handle phx-click attributes. The intention was for them to be handled outside of forms, but technically, we just handle the phx-click first.

LiveViewTest (what PhoenixTest is using underneath) doesn't support testing phx-clicks that only have JS.dispatch/1 in them. So, the combination of PhoenixTest now attempting to handle your phx-click and of LiveViewTest not handling JS.dispatch/1 leads to your test now giving you that "no push or navigation command found within JS commands"

I think PhoenixTest should probably ignore any JS commands that don't have a push or navigate in them. I'll see how to work on this.

germsvel commented 4 weeks ago

@joshk this should now be fixed in main. Got the fix in #139. Please let me know if you upgrade (once I release a new version), and if you continue to see errors.

joshk commented 3 weeks ago

@germsvel my lord you are a legend! I'll this a test run this weekend!