assert module

class assert()

Shorthands for common assertions made in Marionette.

assert.acyclic(obj, error=JavaScriptError, message)

Asserts that an arbitrary object is not acyclic.

Arguments
  • obj (*) – Object to test. This assertion is only meaningful if passed an actual object or array.

  • error (Error) – error Error to throw if assertion fails.

  • message (string) – Custom message to use for error if assertion fails.

Throws

JavaScriptError – If the object is cyclic.

assert.array(obj, msg)

Asserts that <var>obj</var> is an Array.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not an Array.

Returns

Object – <var>obj</var> is returned unaltered.

assert.boolean(obj, msg)

Asserts that <var>obj</var> is a boolean.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not a boolean.

Returns

boolean – <var>obj</var> is returned unaltered.

assert.callable(obj, msg)

Asserts that <var>obj</var> is callable.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not callable.

Returns

function – <var>obj</var> is returned unaltered.

assert.content(context, msg)

Asserts that the current <var>context</var> is content.

Arguments
  • context (string) – Context to test.

  • msg (string) – Custom error message.

Throws

UnsupportedOperationError – If <var>context</var> is not content.

Returns

string – <var>context</var> is returned unaltered.

assert.defined(obj, msg)

Asserts that <var>obj</var> is defined.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not defined.

Returns

? – <var>obj</var> is returned unaltered.

assert.desktop(msg)

Asserts that the current browser is Firefox Desktop or Thunderbird.

Arguments
  • msg (string) – Custom error message.

Throws

UnsupportedOperationError – If current browser is not Firefox or Thunderbird.

assert.fennec(msg)

Asserts that the current browser is Fennec, or Firefox for Android.

Arguments
  • msg (string) – Custom error message.

Throws

UnsupportedOperationError – If current browser is not Fennec.

assert.firefox(msg)

Asserts that the current browser is Firefox Desktop.

Arguments
  • msg (string) – Custom error message.

Throws

UnsupportedOperationError – If current browser is not Firefox.

assert.in(prop, obj, msg)

Asserts that <var>prop</var> is in <var>obj</var>.

Arguments
  • prop (?) – An array element or own property to test if is in <var>obj</var>.

  • obj (?) – An array or an Object that is being tested.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If the <var>obj</var> was an array and did not contain <var>prop</var>. Otherwise if <var>prop</var> is not in <var>obj</var>, or <var>obj</var> is not an object.

Returns

? – The array element, or the value of <var>obj</var>’s own property <var>prop</var>.

assert.integer(obj, msg)

Asserts that <var>obj</var> is an integer.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not an integer.

Returns

number – <var>obj</var> is returned unaltered.

assert.noUserPrompt(dialog, msg)

Asserts that there is no current user prompt.

Arguments
  • dialog (modal.Dialog) – Reference to current dialogue.

  • msg (string) – Custom error message.

Throws

UnexpectedAlertOpenError – If there is a user prompt.

assert.number(obj, msg)

Asserts that <var>obj</var> is a finite number.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not a number.

Returns

number – <var>obj</var> is returned unaltered.

assert.object(obj, msg)

Asserts that <var>obj</var> is an object.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not an object.

Returns

Object – obj| is returned unaltered.

assert.open(browsingContext, msg)

Asserts that the {@link CanonicalBrowsingContext} is open.

Arguments
  • browsingContext (CanonicalBrowsingContext) – Canonical browsing context to check.

  • msg (string) – Custom error message.

Throws

NoSuchWindowError – If <var>browsingContext</var> is no longer open.

Returns

CanonicalBrowsingContext – <var>browsingContext</var> is returned unaltered.

assert.positiveInteger(obj, msg)

Asserts that <var>obj</var> is a positive integer.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not a positive integer.

Returns

number – <var>obj</var> is returned unaltered.

assert.positiveNumber(obj, msg)

Asserts that <var>obj</var> is a positive number.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not a positive integer.

Returns

number – <var>obj</var> is returned unaltered.

assert.session(driver, msg)

Asserts that Marionette has a session.

Arguments
  • driver (GeckoDriver) – Marionette driver instance.

  • msg (string) – Custom error message.

Throws

InvalidSessionIDError – If <var>driver</var> does not have a session ID.

Returns

string – Current session’s ID.

assert.string(obj, msg)

Asserts that <var>obj</var> is a string.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not a string.

Returns

string – <var>obj</var> is returned unaltered.

assert.that(predicate, message, error)

Returns a function that is used to assert the |predicate|.

Arguments
  • predicate (function) – Evaluated on calling the return value of this function. If its return value of the inner function is false, <var>error</var> is thrown with <var>message</var>.

  • message (string) – Custom error message.

  • error (Error) – Custom error type by its class.

Returns

function – Function that takes and returns the passed in value unaltered, and which may throw <var>error</var> with <var>message</var> if <var>predicate</var> evaluates to false.

assert.unsignedShort(obj, msg)

Asserts that <var>obj</var> is an unsigned short number.

Arguments
  • obj (?) – Value to test.

  • msg (string) – Custom error message.

Throws

InvalidArgumentError – If <var>obj</var> is not an unsigned short.

Returns

number – <var>obj</var> is returned unaltered.