Skip to content

Commit

Permalink
Refer to moduletag and describetag
Browse files Browse the repository at this point in the history
  • Loading branch information
ftes committed May 21, 2024
1 parent 97a96f7 commit 023562a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
15 changes: 3 additions & 12 deletions lib/phoenix_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ defmodule PhoenixTest do
end

@doc """
Helper to run tests with the Javascript (Wallaby) driver.
Helper to run tests with the Javascript (Wallaby) driver via `@tag :js`.
Individual tests via `@tag :js`:
```elixir
setup %{conn: conn} = context do
conn = if context[:js], do: with_js_driver(conn), else: conn
Expand All @@ -249,16 +248,8 @@ defmodule PhoenixTest do
end
```
Entire test module:
```elixir
setup, %{conn: conn} do
%{conn: with_js_driver(conn)}
end
test "with wallaby", %{conn: conn} do
visit(conn, "/path")
end
```
You can also use `@describetag :js` and `@moduletag :js`.
Refer to the [ExUnit docs](https://hexdocs.pm/ex_unit/1.16.3/ExUnit.Case.html#module-tags) for more details.
"""
def with_js_driver(%Plug.Conn{} = conn) do
Plug.Conn.assign(conn, :phoenix_test_js, true)
Expand Down
8 changes: 6 additions & 2 deletions test/phoenix_test/wallaby_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ defmodule PhoenixTest.WallabyTest do

import PhoenixTest

setup do
%{conn: PhoenixTest.with_js_driver(Phoenix.ConnTest.build_conn())}
@moduletag :js

setup context do
conn = Phoenix.ConnTest.build_conn()
conn = if context[:js], do: with_js_driver(conn), else: conn
%{conn: conn}
end

describe "unwrap" do
Expand Down

0 comments on commit 023562a

Please sign in to comment.