You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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}doget(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}doget(conn,"/blog")|>assert_response(status,200,path: "/blog",html: "Listing recent posts")|>assert_response(html: Enum.map(posts,&&1.title))end
@jaimeiniesta Hi, just a quick tip to achieve almost the same with the current features: use html: multiple times. This is explicitly allowed per the documentation:
Conditions can be used multiple times within a single call to assert_response. This can be useful to look for multiple text strings in the body.
Your first example then looks like this:
test"Blog post pagination",%{conn: conn}doget(conn,"/blog")|>assert_response(status: 200,path: "/blog",html: "Listing recent posts",html: "Post title 1",html: "Post title 2",html: "Post title 3",html: "Post title 4",html: "Post title 5")end
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?
The text was updated successfully, but these errors were encountered: