Skip to content

Commit aac0497

Browse files
committed
Add refute_timeout opt (default 1ms)
1 parent 78e7688 commit aac0497

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

lib/phoenix_test/playwright.ex

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,7 @@ defmodule PhoenixTest.Playwright do
573573
end
574574

575575
def assert_has(conn, selector, opts) do
576-
if not found?(conn, selector, opts) do
577-
flunk("Could not find element #{selector} #{inspect(opts)}")
578-
end
579-
576+
if not found?(conn, selector, opts), do: flunk("Could not find element #{selector} #{inspect(opts)}")
580577
conn
581578
end
582579

@@ -590,15 +587,14 @@ defmodule PhoenixTest.Playwright do
590587

591588
@doc false
592589
def refute_has(conn, "title", opts) do
590+
opts = Keyword.put_new_lazy(opts, :timeout, fn -> Config.global(:refute_timeout) end)
593591
if not has_title?(conn, opts, is_not: true), do: flunk("Page title matches")
594592
conn
595593
end
596594

597595
def refute_has(conn, selector, opts) do
598-
if found?(conn, selector, opts, is_not: true) do
599-
flunk("Found element #{selector} #{inspect(opts)}")
600-
end
601-
596+
opts = Keyword.put_new_lazy(opts, :timeout, fn -> Config.global(:refute_timeout) end)
597+
if found?(conn, selector, opts, is_not: true), do: flunk("Found element #{selector} #{inspect(opts)}")
602598
conn
603599
end
604600

lib/phoenix_test/playwright/config.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ schema =
6262
default: to_timeout(second: 2),
6363
type: :non_neg_integer
6464
],
65+
refute_timeout: [
66+
default: to_timeout(millisecond: 1),
67+
type: :non_neg_integer
68+
],
6569
slow_mo: [
6670
default: to_timeout(second: 0),
6771
type: :non_neg_integer

test/phoenix_test/playwright_test.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ defmodule PhoenixTest.PlaywrightTest do
55

66
alias ExUnit.AssertionError
77
alias PhoenixTest.Playwright
8+
alias PhoenixTest.Playwright.Config
89

910
describe "visit/2" do
1011
test "navigates to given LiveView page", %{conn: conn} do
@@ -733,7 +734,7 @@ defmodule PhoenixTest.PlaywrightTest do
733734
conn
734735
|> visit("/live/index")
735736
|> click_button("Button with push navigation")
736-
|> refute_has("h1", text: "main page")
737+
|> refute_has("h1", text: "main page", timeout: Config.global(:timeout))
737738
end
738739
end
739740

0 commit comments

Comments
 (0)