Module

Module

Used for creating a group of behavior-based stubs and tests. Modules are like most JavaScript modules: a group of logically related behaviors -- for example, those that would be imported through a require call.

Modules have interfaces that can created through defineMethod (for functions) and defineProperty. Every interface can have multiple Behaviors, that describe how the interface works.

See the Modules & Behaviors Tutorial for more information.

Constructor

new Module(moduleNameopt)

Source:
Tutorials:

Creates a new Module

Parameters:
Name Type Attributes Description
moduleName String <optional>

The optional name for the new module. Currently not used for anything, but may be used in the future for submodule functionality. Using a module name is encouraged for future compatibility.

Methods

defineBehavior(behaviorName, interfaceNameopt) → {Behavior}

Source:

Defines a new behavior for the module.

Parameters:
Name Type Attributes Description
behaviorName String

The name of the behavior

interfaceName String <optional>

An optional interface that the behavior is being defined for

Throws:

If first argument isn't a string or isn't the name of a previously defined behavior. If second argument is specified but isn't a string, or isn't the name of a previously defined interface.

Type
TypeError
Returns:

The Behavior that was created

Type
Behavior

defineMethod(name) → {Interface}

Source:

Defines a new method / funciton interface on the module.

Parameters:
Name Type Description
name String

The name of the interface (i.e. - the key used to access / call the method)

Throws:

If first argument isn't of type String

Type
TypeError
Returns:

The interface that was created

Type
Interface

defineProperty(name) → {Interface}

Source:

Defines a new property interface on the module.

Parameters:
Name Type Description
name String

The name of the interface / property

Throws:

If first argument isn't of type String

Type
TypeError
Returns:

The interface that was created

Type
Interface

defineTest(behaviorName, descopt)

Source:

Specifies that one of the previously defined Behaviors should be tested by the module. Only the behaviors that have been specified through defineTest will be tested. Tests will be run in the order that they are defined.

Parameters:
Name Type Attributes Description
behaviorName String

The name of the behavior to be tested

desc String <optional>

An optional description of the test, similar to what might be passed to the test() or it() function of a test runner. If not specified, the behavior name will be used.

Throws:

If first argument isn't a string or isn't the name of a previously defined behavior. If second argument is provided, but isn't of type String.

Type
TypeError

getBehavior(behaviorName) → {Behavior|undefined}

Source:

Returns the behavior specified by behaviorName

Parameters:
Name Type Description
behaviorName String

The name of the behavior to get

Throws:

If first argument isn't of type String

Type
TypeError
Returns:

The requrested behavior or undefined if the behavior wasn't found

Type
Behavior | undefined

getInterface(interfaceName) → {Interface|undefined}

Source:

Returns the interface specified by interfaceName

Parameters:
Name Type Description
interfaceName String

The name of the interface to get

Throws:

If first argument isn't of type String

Type
TypeError
Returns:

The requrested interface or undefined if the interface wasn't found

Type
Interface | undefined

getStub(behaviorName) → {Wrapper}

Source:

Returns a stub Wrapper for the specified behavior.

Parameters:
Name Type Description
behaviorName String

The behavior to create a stub for

Throws:

If first argument isn't of type String

Type
TypeError
Returns:

A stub that performs the specified behavior

Type
Wrapper

getTest(behaviorName, module) → {function|undefined}

Source:

Looks up a test for the behavior specified by behaviorName

Parameters:
Name Type Description
behaviorName String

The behavior that a test has been defined for

module Object

The module to be tested

Returns:

The function for running the test or undefined

Type
function | undefined

getTestList() → {Array.<Module#Test>}

Source:

Returns an array of tests.

Returns:

An array of test objects. Each object has a desc and fn that is ready to be passed to a test runner, such as Mocha, Jasmine, or QUnit.

Type
Array.<Module#Test>

runAllTests(mod, cb)

Source:

Runs all the tests in the testList.

Parameters:
Name Type Description
mod Object

The module to be tested. Should support all the interfaces and behaviors that will be tested.

cb function

A callback that receives the arguments description and function for each test to be run. Most testing framworks can simply pass a test or it function.

Type Definitions

Test

Source:
Properties:
Name Type Description
behaviorName String

The name of the behavior to be tested

desc String

A short description of the test...[any]

fn function

The function that runs the test. No arguments required and no return value. Throws on failure.

Type:
  • Object