BaseTestSuite

All brs files that include '@TestSuite annotations automatically extend the BaseTestSuite. The base test suite contains all of the assertions, and utility methods required to writey our tests, as well as being responsible for tracking the state of the tests and groups.

Methods

addTest(name, func)

Add a test to a suite's test cases array. Used internally.

Source:
Parameters:
Name Type Description
name Dynamic

A test name.

func Dynamic

A test function name.

assertAAContainsSubset(array, subset, ignoredFields, msgopt) → {boolean}

Asserts the associative array contains the fields contained in subset; while ignoring the fields in the ignoredFields array

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

associative array to check

subset Dynamic

associative array of values to check for

ignoredFields Dynamic

array of fieldnames to ignore while comparing

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertAAHasKey(array, key, msgopt) → {boolean}

Fail if the array doesn't have the key.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

key Dynamic

key name

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertAAHasKeys(array, keys, msgopt) → {boolean}

Fail if the array doesn't have the keys list.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

A target associative array.

keys Dynamic

Array of key names.

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertAANotHasKey(array, key, msgopt) → {boolean}

Fail if the array has the key.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

key Dynamic

key name

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertAANotHasKeys(array, keys, msgopt) → {boolean}

Fail if the array has the keys list.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

A target associative array.

keys Dynamic

Array of key names.

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayContains(array, value, key, msgopt) → {boolean}

Fail if the array doesn't have the item.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

value Dynamic

value to check - value to check for

key Dynamic

key name in associative array

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayContainsAAs(array, values, msgopt) → {boolean}

Fail if the array does not contain all of the aa's in the values array.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

values Dynamic

array of aas to look for in target array

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayContainsOnlyValuesOfType(array, typeStr, msgopt) → {boolean}

Fail if the array doesn't contains items of specific type only.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

typeStr Dynamic

type name - must be String, Array, Boolean, or AssociativeArray

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayContainsSubset(array, subset, msgopt) → {boolean}

Fail if the array doesn't have the item subset.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

subset Dynamic

items to check presnece of

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayCount(array, count, msgopt) → {boolean}

Fail if the array items count <> expected count

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

count Dynamic

An expected array items count

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayNotContains(array, array, value, key, msgopt) → {boolean}

Fail if the array has the item.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

array Dynamic

target array

value Dynamic

value to check - Value to check for

key Dynamic

A key name for associative array.

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayNotContainsSubset(array, subset, msgopt) → {boolean}

Fail if the array have the item from subset.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

subset Dynamic

items to check presnece of

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertArrayNotCount(array, count, msgopt) → {boolean}

Fail if the array items count = expected count.

Source:
Parameters:
Name Type Attributes Default Description
array Dynamic

target array

count Dynamic

An expected array items count.

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertEmpty(item, msgopt) → {boolean}

Fail if the item is not empty array or string.

Source:
Parameters:
Name Type Attributes Default Description
item Dynamic

item to check

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertEqual(first, second, msgopt) → {boolean}

Fail if the two objects are unequal as determined by the '<>' operator.

Source:
Parameters:
Name Type Attributes Default Description
first Dynamic

first object to compare

second Dynamic

second object to compare

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertFalse(expr, msgopt)

Fail the test if the expression is true.

Source:
Parameters:
Name Type Attributes Default Description
expr Dynamic

An expression to evaluate.

msg Dynamic <optional>
""

alternate error message ' Default value: "Expression evaluates to true"* @returns {boolean} - true if the assert was satisfied, false otherwise

assertInvalid(value, msgopt) → {boolean}

Fail if the value is not invalid.

Source:
Parameters:
Name Type Attributes Default Description
value Dynamic

value to check - value to check for

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertLike(first, second, msgopt) → {boolean}

does a fuzzy comparison

Source:
Parameters:
Name Type Attributes Default Description
first Dynamic

first object to compare

second Dynamic

second object to compare

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertMocks()

Will check all mocks that have been created to ensure they were invoked the expected amount of times, with the expected args.

Source:

assertNodeContains(node, value, msgopt) → {boolean}

Asserts the node contains the child value

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

a node to check

value Dynamic

value to check - value to look for

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNodeContainsFields(node, subset, msgopt) → {boolean}

Fail if the node doesn't have the item subset.

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

A target node

subset Dynamic

items to check

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNodeContainsOnly(node, value, msgopt) → {boolean}

Asserts the node contains only the child value

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

a node to check

value Dynamic

value to check - value to look for

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNodeCount(node, count, msgopt) → {boolean}

Asserts that the node contains the desginated number of children

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

target node

count Dynamic

expected number of child items

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert w, false otherwise

assertNodeEmpty(node, msgopt) → {boolean}

Asserts the node has no children

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

a node to check

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNodeNotContains(node, value, msgopt) → {boolean}

Fail if the node h item.

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

A target node

value Dynamic

value to check - a node child

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNodeNotContainsFields(node, subset, msgopt) → {boolean}

Fail if the node have the item from subset.

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

A target node

subset Dynamic

the items to check for

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert w, false otherwise

assertNodeNotCount(node, count, msgopt) → {boolean}

Fail if the node items count = expected count.

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

A target node

count Dynamic

Expected item count

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNodeNotEmpty(node, msgopt) → {boolean}

Asserts the node has children

Source:
Parameters:
Name Type Attributes Default Description
node Dynamic

a node to check

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNotEmpty(item, msgopt) → {boolean}

Fail if the item is empty array or string.

Source:
Parameters:
Name Type Attributes Default Description
item Dynamic

item to check

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNotEqual(first, second, msgopt) → {boolean}

Fail if the two objects are equal as determined by the '=' operator.

Source:
Parameters:
Name Type Attributes Default Description
first Dynamic

first object to compare

second Dynamic

second object to compare

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertNotInvalid(value, msgopt) → {boolean}

Fail if the value is invalid.

Source:
Parameters:
Name Type Attributes Default Description
value Dynamic

value to check - value to check for

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertSubType(value, typeStr, msgopt) → {boolean}

Asserts that the value is a node of designated subtype

Source:
Parameters:
Name Type Attributes Default Description
value Dynamic

value to check - target node

typeStr Dynamic

type name

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertTrue(expr, msgopt) → {boolean}

Fail the test unless the expression is true.

Source:
Parameters:
Name Type Attributes Default Description
expr Dynamic

An expression to evaluate.

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

assertType(value, typeStr, msgopt) → {boolean}

Asserts that the value is a node of designated type

Source:
Parameters:
Name Type Attributes Default Description
value Dynamic

value to check - target node

typeStr Dynamic

type name

msg Dynamic <optional>
""

alternate error message

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

cleanMocks()

Cleans up all tracking data associated with mocks

Source:

cleanStubs()

Cleans up all tracking data associated with stubs

Source:

createFake(target, methodName, expectedInvocationsopt, expectedArgsopt, returnValueopt) → {Object}

Creates a stub to replace a real method with. This is used internally.

Source:
Parameters:
Name Type Attributes Default Description
target Dynamic

object on which the method to be stubbed is found

methodName Dynamic

name of method to stub

expectedInvocations Dynamic <optional>
1

number of invocations we expect

expectedArgs Dynamic <optional>
invalid

array containing the arguments we expect the method to be invoked with

returnValue Dynamic <optional>
invalid

value that the stub method will return when invoked

Returns:
Type:
Object
  • stub that was wired into the real method

createTest(name, func)

Create a test object. Used internally

Source:
Parameters:
Name Type Description
name Dynamic

A test name.

func Dynamic

A test function name.

expect(target, methodName, expectedInvocationsopt, expectedArgsopt, returnValueopt, allowNonExistingMethodsopt) → {Object}

Creates a stub to replace a real method with, which the framework will track. If it was invoked the wrong number of times, or with wrong arguments, it will result in test failure

Source:
Parameters:
Name Type Attributes Default Description
target Dynamic

object on which the method to be stubbed is found

methodName Dynamic

name of method to stub

expectedInvocations Dynamic <optional>
1

number of invocations we expect

expectedArgs Dynamic <optional>
invalid

array containing the arguments we expect the method to be invoked with

returnValue Dynamic <optional>
invalid

value that the stub method will return when invoked

allowNonExistingMethods boolean <optional>
false

if true, then rooibos will only warn if the method did not exist prior to faking

Returns:
Type:
Object
  • mock that was wired into the real method

expectNone(target, methodName, allowNonExistingMethodsopt) → {Object}

Creates a stub to replace a real method with, which the framework will track. If it was invoked, it will result in test failure

Source:
Parameters:
Name Type Attributes Default Description
target Dynamic

object on which the method to be stubbed is found

methodName Dynamic

name of method to stub

allowNonExistingMethods boolean <optional>
false

if true, then rooibos will only warn if the method did not exist prior to faking

Returns:
Type:
Object
  • mock that was wired into the real method

expectOnce(target, methodName, expectedArgsopt, returnValueopt, allowNonExistingMethodsopt) → {Object}

Creates a stub to replace a real method with, which the framework will track. If it was invoked the wrong number of times, or with wrong arguments, it will result in test failure

Source:
Parameters:
Name Type Attributes Default Description
target Dynamic

object on which the method to be stubbed is found

methodName Dynamic

name of method to stub

expectedArgs Dynamic <optional>
invalid

array containing the arguments we expect the method to be invoked with

returnValue Dynamic <optional>
invalid

value that the stub method will return when invoked

allowNonExistingMethods boolean <optional>
false

if true, then rooibos will only warn if the method did not exist prior to faking

Returns:
Type:
Object
  • mock that was wired into the real method

expectOnceOrNone(target, methodName, isExpected, expectedArgsopt, returnValueopt, allowNonExistingMethodsopt) → {Object}

Toggles between expectOnce and expectNone, to allow for easy paremeterized expect behaviour

Source:
Parameters:
Name Type Attributes Default Description
target Dynamic

object on which the method to be stubbed is found

methodName Dynamic

name of method to stub

isExpected Dynamic

if true, then this is the same as expectOnce, if false, then this is the same as expectNone

expectedArgs Dynamic <optional>
invalid

array containing the arguments we expect the method to be invoked with

returnValue Dynamic <optional>
invalid

value that the stub method will return when invoked

allowNonExistingMethods boolean <optional>
false

if true, then rooibos will only warn if the method did not exist prior to faking

Returns:
Type:
Object
  • mock that was wired into the real method

fail(msgopt) → {boolean}

Fail immediately, with the given message

Source:
Parameters:
Name Type Attributes Default Description
msg Dynamic <optional>
""

message to display in the test report

Returns:
Type:
boolean
  • true if the assert was satisfied, false otherwise

g(aa, subset, path) → {dynamic}

ripped and adapted from rodash - thanks @veeta! use this method to safely get anything. useful for when unit testing a collection or something and you're not sure if it's gonna crash!

Source:
Parameters:
Name Type Description
aa Dynamic

node, array or assoArray

subset Dynamic

the items to check for

path Dynamic

as string path to target field. Can use .0. or [0] index notation e.g. "children.0.title" or "children[0].title"

Returns:
Type:
dynamic
  • matched item, on aa at path

mock(target, methodName, expectedInvocations, expectedArgsopt, returnValueopt, allowNonExistingMethodsopt) → {Object}

Creates a stub to replace a real method with, which the framework will track. If it was invoked the wrong number of times, or with wrong arguments, it will result in test failure

Source:
Parameters:
Name Type Attributes Default Description
target Dynamic

object on which the method to be stubbed is found

methodName Dynamic

name of method to stub

expectedInvocations Dynamic

number of invocations we expect

expectedArgs Dynamic <optional>
invalid

array containing the arguments we expect the method to be invoked with

returnValue Dynamic <optional>
invalid

value that the stub method will return when invoked

allowNonExistingMethods boolean <optional>
false

if true, then rooibos will only warn if the method did not exist prior to faking

Returns:
Type:
Object
  • mock that was wired into the real method

stub(target, methodName, returnValueopt, allowNonExistingMethodsopt) → {Object}

Creates a stub to replace a real method with

Source:
Parameters:
Name Type Attributes Default Description
target Dynamic

object on which the method to be stubbed is found

methodName Dynamic

name of method to stub

returnValue Dynamic <optional>
invalid

value that the stub method will return when invoked

allowNonExistingMethods boolean <optional>
false

if true, then rooibos will only warn if the method did not exist prior to faking

Returns:
Type:
Object
  • stub that was wired into the real method