assert module

class assert()

Shorthands for common assertions made in Marionette.

assert.acyclic(obj, msg, error)

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 (?) – Own property to test if is in <var>obj</var>.
  • obj (?) – Object.
  • msg (string) – Custom error message.
Throws:

InvalidArgumentError – If <var>prop</var> is not in <var>obj</var>, or <var>obj</var> is not an object.

Returns:

? – 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(context, msg)

Asserts that the {@link ChromeWindow} is open or that the {@link browser.Context} has a content browser attached.

When passed in a {@link ChromeContext} this is equivalent to testing that the associated <code>window</code> global is open, and when given {@link browser.Context} it will test that the content frame, represented by <code>&lt;xul:browser&gt;</code>, is connected.

Arguments:
  • context (ChromeWindow|browser.Context) – Browsing context to test.
  • msg (string) – Custom error message.
Throws:

NoSuchWindowError – If <var>context</var>’s <code>window</code> has been closed.

Returns:

ChromeWindow|browser.Context – <var>context</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.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.