Skip to content

Commit 4c36568

Browse files
authored
fix: allow refute_redirect to refute any redirections (#3729)
1 parent 68b70e0 commit 4c36568

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/phoenix_live_view/test/live_view_test.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,11 +1462,17 @@ defmodule Phoenix.LiveViewTest do
14621462
14631463
It returns :ok if the specified redirect isn't already in the mailbox.
14641464
1465+
If no path is specified, refutes any redirection on the given view.
1466+
14651467
## Examples
14661468
14671469
render_click(view, :event_that_triggers_redirect_to_path)
14681470
:ok = refute_redirected view, "/wrong_path"
14691471
"""
1472+
def refute_redirected(view) do
1473+
refute_navigation(view, :redirect, nil)
1474+
end
1475+
14701476
def refute_redirected(view, to) when is_binary(to) do
14711477
refute_navigation(view, :redirect, to)
14721478
end
@@ -1481,7 +1487,7 @@ defmodule Phoenix.LiveViewTest do
14811487
"expected #{inspect(view.module)} not to #{kind}, "
14821488
end
14831489

1484-
raise ArgumentError, message <> "but got a #{kind} to #{inspect(to)}"
1490+
raise ArgumentError, message <> "but got a #{kind} to #{inspect(new_to)}"
14851491
after
14861492
0 -> :ok
14871493
end

test/phoenix_live_view/integrations/nested_test.exs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ defmodule Phoenix.LiveView.NestedTest do
200200
assert %ArgumentError{message: message} = e
201201
assert message =~ "not to redirect to"
202202
end
203+
204+
send(
205+
clock_view.pid,
206+
{:run,
207+
fn socket ->
208+
{:noreply, LiveView.push_navigate(socket, to: "/any_url")}
209+
end}
210+
)
211+
212+
try do
213+
refute_redirected(thermo_view)
214+
rescue
215+
e ->
216+
assert %ArgumentError{message: message} = e
217+
assert message =~ "not to redirect, but got a redirect to /any_url"
218+
end
203219
end
204220

205221
@tag session: %{nest: []}

0 commit comments

Comments
 (0)