Hello!
I want to test a blog that paginates posts, showing 5 per page. I'd like to get the post list, and check that I can find the post title of the first 10 posts, something like this:
test "Blog post pagination", %{conn: conn} do
get(conn, "/blog")
|> assert_response(status, 200, path: "/blog", html: "Listing recent posts")
|> assert_response(html: "Post title 1")
|> assert_response(html: "Post title 2")
|> assert_response(html: "Post title 3")
|> assert_response(html: "Post title 4")
|> assert_response(html: "Post title 5")
end
Instead of this, it would be great if we could pass a list of strings to :html, so we could do this:
test "Blog post pagination", %{conn: conn, posts: posts} do
get(conn, "/blog")
|> assert_response(status, 200, path: "/blog", html: "Listing recent posts")
|> assert_response(html: Enum.map(posts, & &1.title))
end
Or this, check for different strings explicitly:
test "Pricing plans", %{conn: conn} do
get(conn, "/pricing")
|> assert_response(status, 200,
path: "/pricing",
html: [
"Pricing",
"Starter plan",
"Pro plan",
"Enterprise plan"
]
)
end
Same for refute_response.
What do you think?
Hello!
I want to test a blog that paginates posts, showing 5 per page. I'd like to get the post list, and check that I can find the post title of the first 10 posts, something like this:
Instead of this, it would be great if we could pass a list of strings to
:html, so we could do this:Or this, check for different strings explicitly:
Same for
refute_response.What do you think?