Test Application Stub

T3.js provides a test bundle for unit testing. This package contains most of the core components and a stubbed version of the Application object. We recommend using this package instead of the core T3.js code for testing your components. Check out the T3 Testing Bundle Guide for more information.

Box.Application

Description

This object is a stripped down version of the actual Box.Application that allows better unit testing.


addService

Description

Register a T3 Service component.

Usage

Parameter Type Description
name string Name of service.
creator Function Creator function for the service.

Returns

The Box.Application object (for chaining purposes).

Example

Box.Application.addService('some-service', function(application) {
    return {
        foo: function() { ... }
    };
});

addModule

Description

Register a T3 Module component.

Usage

Parameter Type Description
name string Name of module.
creator Function Creator function for the module.

Returns

The Box.Application object (for chaining purposes).

Example

Box.Application.addModule('some-module', function(context) {
    return {
        init: function() { ... },
        destroy: function() { ... }
    };
});

addBehavior

Description

Register a T3 Behavior component.

Usage

Parameter Type Description
name string Name of behavior.
creator Function Creator function for the behavior.

Returns

The Box.Application object (for chaining purposes).

Example

Box.Application.addBehavior('some-behavior', function(context) {
    return {
        init: function() { ... },
        destroy: function() { ... }
    };
});

hasService

Description

Checks if a service has been registered.

Usage

Parameter Type Description
service string Name of service.

getServiceForTest

Description

Retrieves an instance of a registered service with a TestServiceProvider object.

Usage

Parameter Type Description
service string Name of service.
serviceProvider TestServiceProvider A test service provider object.

Example

Box.Application.getServiceForTest('some-service', new Box.TestServiceProvider({
    logger: {
        warn: function() {}
    }
});

getModuleForTest

Description

Retrieves an instance of a registered module with a TestServiceProvider object.

Usage

Parameter Type Description
module string Name of module.
serviceProvider TestServiceProvider A test service provider object.

Example

Box.Application.getModuleForTest('some-module', new Box.TestServiceProvider({
    logger: {
        warn: function() {}
    }
});

getModuleForTest

Description

Retrieves an instance of a registered module with a TestServiceProvider object.

Usage

Parameter Type Description
module string Name of module.
serviceProvider TestServiceProvider A test service provider object.

Example

Box.Application.getModuleForTest('some-module', new Box.TestServiceProvider({
    logger: {
        warn: function() {}
    }
});

getBehaviorForTest

Description

Retrieves an instance of a registered behavior with a TestServiceProvider object.

Usage

Parameter Type Description
behavior string Name of behavior.
serviceProvider TestServiceProvider A test service provider object.

Example

Box.Application.getBehaviorForTest('some-behavior', new Box.TestServiceProvider({
    logger: {
        warn: function() {}
    }
});

reset

Description

Unregisters all services, modules, and behaviors

Example

Box.Application.reset();