Last active
July 18, 2025 20:12
-
-
Save joeytrapp/d31b4df0559fd3d9f43d58b8841a6680 to your computer and use it in GitHub Desktop.
Demonstration of phoenix_test 0.7.0 uncheck/3 not working with phx-click and phx-value attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIT License | |
© 2025 Apple Inc. All rights reserved. | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ elixir uncheck_bug.exs | |
Running ExUnit with seed: 632994, max_cases: 32 | |
15:08:32.696 [error] GenServer #PID<0.277.0> terminating | |
** (FunctionClauseError) no function clause matching in Demo.DemoLive.handle_event/3 | |
uncheck_bug.exs:33: Demo.DemoLive.handle_event("toggle_selected", %{}, #Phoenix.LiveView.Socket<id: "phx-GFNxWk7AFk3-3xOB", endpoint: PhoenixPlayground.Endpoint, view: PhoenixPlayground.Router.DelegateLive, parent_pid: nil, root_pid: #PID<0.277.0>, router: PhoenixPlayground.Router.LiveRouter, assigns: %{selected: %{"abc" => true}, __changed__: %{}, flash: %{}, live_action: :index}, transport_pid: #PID<0.276.0>, sticky?: nil, ...>) | |
(phoenix_live_view 1.0.17) lib/phoenix_live_view/channel.ex:509: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3 | |
(telemetry 1.3.0) /Users/joey/Library/Caches/mix/installs/elixir-1.18.2-erts-15.2/3a8b4b66ef7198d90cc9274c3d0c1c4e/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3 | |
(phoenix_live_view 1.0.17) lib/phoenix_live_view/channel.ex:260: Phoenix.LiveView.Channel.handle_info/2 | |
(stdlib 6.2) gen_server.erl:2345: :gen_server.try_handle_info/3 | |
(stdlib 6.2) gen_server.erl:2433: :gen_server.handle_msg/6 | |
(stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3 | |
Last message: %Phoenix.Socket.Message{topic: "lv:phx-GFNxWk7AFk3-3xOB", event: "event", payload: %{"event" => "toggle_selected", "type" => "click", "value" => %{}}, ref: "2", join_ref: 0} | |
15:08:32.706 [error] GenServer #PID<0.237.0> terminating | |
** (FunctionClauseError) no function clause matching in Demo.DemoLive.handle_event/3 | |
uncheck_bug.exs:33: Demo.DemoLive.handle_event("toggle_selected", %{}, #Phoenix.LiveView.Socket<id: "phx-GFNxWk7AFk3-3xOB", endpoint: PhoenixPlayground.Endpoint, view: PhoenixPlayground.Router.DelegateLive, parent_pid: nil, root_pid: #PID<0.277.0>, router: PhoenixPlayground.Router.LiveRouter, assigns: %{selected: %{"abc" => true}, __changed__: %{}, flash: %{}, live_action: :index}, transport_pid: #PID<0.276.0>, sticky?: nil, ...>) | |
(phoenix_live_view 1.0.17) lib/phoenix_live_view/channel.ex:509: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3 | |
(telemetry 1.3.0) /Users/joey/Library/Caches/mix/installs/elixir-1.18.2-erts-15.2/3a8b4b66ef7198d90cc9274c3d0c1c4e/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3 | |
(phoenix_live_view 1.0.17) lib/phoenix_live_view/channel.ex:260: Phoenix.LiveView.Channel.handle_info/2 | |
(stdlib 6.2) gen_server.erl:2345: :gen_server.try_handle_info/3 | |
(stdlib 6.2) gen_server.erl:2433: :gen_server.handle_msg/6 | |
(stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3 | |
Last message: {:EXIT, #PID<0.236.0>, {:function_clause, [{Demo.DemoLive, :handle_event, ["toggle_selected", %{}, #Phoenix.LiveView.Socket<id: "phx-GFNxWk7AFk3-3xOB", endpoint: PhoenixPlayground.Endpoint, view: PhoenixPlayground.Router.DelegateLive, parent_pid: nil, root_pid: #PID<0.277.0>, router: PhoenixPlayground.Router.LiveRouter, assigns: %{selected: %{"abc" => true}, __changed__: %{}, flash: %{}, live_action: :index}, transport_pid: #PID<0.276.0>, sticky?: nil, ...>], [file: ~c"uncheck_bug.exs", line: 33]}, {Phoenix.LiveView.Channel, :"-view_handle_event/3-fun-0-", 3, [file: ~c"lib/phoenix_live_view/channel.ex", line: 509]}, {:telemetry, :span, 3, [file: ~c"/Users/joey/Library/Caches/mix/installs/elixir-1.18.2-erts-15.2/3a8b4b66ef7198d90cc9274c3d0c1c4e/deps/telemetry/src/telemetry.erl", line: 324]}, {Phoenix.LiveView.Channel, :handle_info, 2, [file: ~c"lib/phoenix_live_view/channel.ex", line: 260]}, {:gen_server, :try_handle_info, 3, [file: ~c"gen_server.erl", line: 2345]}, {:gen_server, :handle_msg, 6, [file: ~c"gen_server.erl", line: 2433]}, {:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 329]}]}} | |
1) test uncheck fails with phx-click and phx-value (Demo.DemoLiveTest) | |
uncheck_bug.exs:55 | |
** (EXIT from #PID<0.236.0>) an exception was raised: | |
** (FunctionClauseError) no function clause matching in Demo.DemoLive.handle_event/3 | |
The following arguments were given to Demo.DemoLive.handle_event/3: | |
# 1 | |
"toggle_selected" | |
# 2 | |
%{} | |
# 3 | |
#Phoenix.LiveView.Socket<id: "phx-GFNxWk7AFk3-3xOB", endpoint: PhoenixPlayground.Endpoint, view: PhoenixPlayground.Router.DelegateLive, parent_pid: nil, root_pid: #PID<0.277.0>, router: PhoenixPlayground.Router.LiveRouter, assigns: %{selected: %{"abc" => true}, __changed__: %{}, flash: %{}, live_action: :index}, transport_pid: #PID<0.276.0>, sticky?: nil, ...> | |
stacktrace: | |
uncheck_bug.exs:33: Demo.DemoLive.handle_event/3 | |
(phoenix_live_view 1.0.17) lib/phoenix_live_view/channel.ex:509: anonymous fn/3 in Phoenix.LiveView.Channel.view_handle_event/3 | |
(telemetry 1.3.0) /Users/joey/Library/Caches/mix/installs/elixir-1.18.2-erts-15.2/3a8b4b66ef7198d90cc9274c3d0c1c4e/deps/telemetry/src/telemetry.erl:324: :telemetry.span/3 | |
(phoenix_live_view 1.0.17) lib/phoenix_live_view/channel.ex:260: Phoenix.LiveView.Channel.handle_info/2 | |
(stdlib 6.2) gen_server.erl:2345: :gen_server.try_handle_info/3 | |
(stdlib 6.2) gen_server.erl:2433: :gen_server.handle_msg/6 | |
(stdlib 6.2) proc_lib.erl:329: :proc_lib.init_p_do_apply/3 | |
Finished in 0.07 seconds (0.01s on load, 0.00s async, 0.06s sync) | |
1 test, 1 failure |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mix.install( | |
[ | |
{:phoenix_playground, "~> 0.1.6"}, | |
{:phoenix_test, "0.7.0"} | |
], | |
config: [ | |
phoenix_test: [endpoint: PhoenixPlayground.Endpoint] | |
] | |
) | |
defmodule Demo.DemoLive do | |
use Phoenix.LiveView | |
def mount(_params, _session, socket) do | |
{:ok, assign(socket, selected: %{})} | |
end | |
def render(assigns) do | |
~H""" | |
<label> | |
<span>Item (abc)</span> | |
<input | |
type="checkbox" | |
id="checkbox-abc" | |
checked={@selected["abc"]} | |
phx-click="toggle_selected" | |
phx-value-id="abc" | |
/> | |
</label> | |
""" | |
end | |
def handle_event("toggle_selected", %{"id" => id}, socket) do | |
selected = socket.assigns.selected | |
selected = | |
if Map.has_key?(selected, id) do | |
Map.delete(selected, id) | |
else | |
Map.put(selected, id, true) | |
end | |
{:noreply, assign(socket, :selected, selected)} | |
end | |
end | |
Logger.configure(level: :warning) | |
ExUnit.start() | |
defmodule Demo.DemoLiveTest do | |
use ExUnit.Case | |
use PhoenixPlayground.Test, live: Demo.DemoLive | |
import PhoenixTest | |
test "uncheck fails with phx-click and phx-value" do | |
build_conn() | |
|> visit("/") | |
|> assert_has("input[type=checkbox]:not(:checked)") | |
|> check("#checkbox-abc", "abc", exact: false) | |
|> assert_has("input[type=checkbox]:checked") | |
|> uncheck("#checkbox-abc", "abc", exact: false) | |
|> assert_has("input[type=checkbox]:not(:checked)") | |
end | |
end |
Comments are disabled for this gist.