-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule DomHelpers.Assertions do | ||
@moduledoc """ | ||
This module contains some extra helpers specially for assertions, | ||
though is preferred to use direct comparisons with the different | ||
[selectors](`DomHelpers.Selectors`) and [accessors](`DomHelpers.Accessors`). | ||
""" | ||
|
||
import DomHelpers.Accessors | ||
|
||
@doc """ | ||
Checks if the given selector is found at least once | ||
in the given document. Works like [`has_element?/2`](`Phoenix.LiveViewTest.has_element?/2`) | ||
but with the parameters reversed so you can pipe when | ||
building the selector. | ||
## Example | ||
``` | ||
iex> "li" |> is_in?("<ul><li>First</li><li>Second</li></ul>") | ||
true | ||
iex> "li" |> is_in?("<ul><li>First</li></ul>") | ||
true | ||
iex> "span" |> is_in?("<ul><li>First</li></ul>") | ||
false | ||
``` | ||
""" | ||
def is_in?(selector, htmlable) do | ||
find_count(htmlable, selector) > 0 | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
defmodule DomHelpers.AssertionsTest do | ||
@moduledoc false | ||
use DomHelpers.Case | ||
|
||
import DomHelpers.Assertions | ||
|
||
doctest DomHelpers.Assertions | ||
end |