PhoenixIntegration.Assertions.assert_response

You're seeing just the function assert_response, go back to PhoenixIntegration.Assertions module for more information.
Link to this function

assert_response(conn, conditions)

View Source

Asserts a set of conditions against the response fields of a conn. Returns the conn on success so that it can be used in the next integration call.

Parameters

  • conn should be a conn returned from a previous request should point to the path being redirected to.
  • conditions a list of conditions to test against. Conditions can include:
    • :status checks that conn.status equals the given numeric value
    • :content_type the conn's content-type header should contain the given text. Typical values are "text/html" or "application/json"
    • :body conn.resp_body should contain the given text. Does not check the content_type.
    • :html checks that content_type is html, then looks for the given text in the body.
    • :json checks that content_type is json, then checks that the json data equals the given map.
    • :path the route rendered into the conn must equal the given path (or uri).
    • :uri same as :path
    • :redirect checks that conn.status is 302 and that the path in the "location" redirect header equals the given path.
    • :to same as :redirect
    • :assigns checks that conn.assigns contains the given values, which could be in the form of %{key => value} or [{key, value}]
    • :value checks that the value returned by a callback (in the form fn(conn)) is truthy

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.

Example

# test a rendered page
assert_response( conn,
  status:   200,
  path:     page_path(conn, :index),
  html:     "Some Content",
  html:     "More Content",
  assigns:  %{current_user_id: user.id}
)

# test a redirection
assert_response( conn, to: page_path(conn, :index) )

# test a callback value
assert_response( conn, value: fn(conn) ->
  Guardian.Plug.current_resource(conn)
end)