Fluffy.Expect (Fluffy v0.2.0)

Copy Markdown View Source

Typed locator, active-page, and captured-result assertion values executed by Fluffy.expect/2.

Active page expectations live on Fluffy.Page. Captured-result expectations live on Fluffy.Download, Fluffy.Dialog, Fluffy.Navigation, Fluffy.Request, and Fluffy.Response.

Assertion constructors use fluent to_be_* names for states and to_have_* names for properties, matching the page assertions in Fluffy.Page.

Every expectation constructor accepts the shared timeout option. Captured-result assertions inspect an already retained result immediately; their timeout option does not wait for another event. Set the capture timeout on Fluffy.wait_for/4.

  • :timeout (non_neg_integer/0) - Maximum time in milliseconds to wait for the operation.

to_be_checked/2 additionally accepts:

  • :timeout (non_neg_integer/0) - Maximum time in milliseconds to wait for the operation.

  • :checked (boolean/0) - Set to false to expect an unchecked control.

  • :indeterminate (boolean/0) - Expect the browser-owned indeterminate state.

Summary

Locator assertions

to_be_checked(locator, options \\ [])

@spec to_be_checked(Fluffy.Locator.t(), [checked_option()]) :: t()

Expects a checkbox or radio to have Playwright's checked state.

The default is checked. Pass checked: false for unchecked, or indeterminate: true for the browser-owned mixed state. The indeterminate state requires Playwright because it is a DOM property rather than HTML state available to the Static or LiveView drivers.

to_be_disabled(locator, options \\ [])

@spec to_be_disabled(Fluffy.Locator.t(), [option()]) :: t()

to_be_editable(locator, options \\ [])

@spec to_be_editable(Fluffy.Locator.t(), [option()]) :: t()

to_be_enabled(locator, options \\ [])

@spec to_be_enabled(Fluffy.Locator.t(), [option()]) :: t()

to_be_focused(locator, options \\ [])

@spec to_be_focused(Fluffy.Locator.t(), [option()]) :: t()

to_be_visible(locator, options \\ [])

@spec to_be_visible(Fluffy.Locator.t(), [option()]) :: t()

to_have_count(locator, expected, options \\ [])

@spec to_have_count(Fluffy.Locator.t(), non_neg_integer(), [option()]) :: t()

to_have_value(locator, expected, options \\ [])

@spec to_have_value(Fluffy.Locator.t(), String.t(), [option()]) :: t()

to_have_values(locator, expected, options \\ [])

@spec to_have_values(Fluffy.Locator.t(), [term()], [option()]) :: t()

Types

checked_option()

@type checked_option() ::
  {:timeout, non_neg_integer()}
  | {:checked, boolean()}
  | {:indeterminate, boolean()}

kind()

@type kind() ::
  :checked
  | :count
  | :disabled
  | :editable
  | :enabled
  | :focused
  | :opener
  | :status
  | :title
  | :url
  | :value
  | :values
  | :visible
  | :download_content
  | :download_content_type
  | :download_size
  | :download_suggested_filename
  | :download_url
  | :dialog_action
  | :dialog_default_value
  | :dialog_message
  | :dialog_prompt_text
  | :dialog_type
  | :navigation_from_url
  | :navigation_status
  | :navigation_url
  | :request_headers
  | :request_method
  | :request_page
  | :request_post_data
  | :request_resource_type
  | :request_url
  | :response_headers
  | :response_method
  | :response_page
  | :response_post_data
  | :response_resource_type
  | :response_status
  | :response_status_text
  | :response_url

option()

@type option() :: {:timeout, non_neg_integer()}

t()

@type t() :: %Fluffy.Expect{
  expected: term(),
  kind: kind(),
  negated?: boolean(),
  options: keyword(),
  target: target()
}

target()

@type target() ::
  {:locator, Fluffy.Locator.t()}
  | :page
  | {:download, term()}
  | {:dialog, term()}
  | {:navigation, term()}
  | {:request, term()}
  | {:response, term()}