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.
This object is a stripped down version of the actual Box.Application that allows better unit testing.
Register a T3 Service component.
Parameter | Type | Description |
---|---|---|
name | string | Name of service. |
creator | Function | Creator function for the service. |
The Box.Application
object (for chaining purposes).
Box.Application.addService('some-service', function(application) {
return {
foo: function() { ... }
};
});
Register a T3 Module component.
Parameter | Type | Description |
---|---|---|
name | string | Name of module. |
creator | Function | Creator function for the module. |
The Box.Application
object (for chaining purposes).
Box.Application.addModule('some-module', function(context) {
return {
init: function() { ... },
destroy: function() { ... }
};
});
Register a T3 Behavior component.
Parameter | Type | Description |
---|---|---|
name | string | Name of behavior. |
creator | Function | Creator function for the behavior. |
The Box.Application
object (for chaining purposes).
Box.Application.addBehavior('some-behavior', function(context) {
return {
init: function() { ... },
destroy: function() { ... }
};
});
Checks if a service has been registered.
Parameter | Type | Description |
---|---|---|
service | string | Name of service. |
Retrieves an instance of a registered service with a TestServiceProvider
object.
Parameter | Type | Description |
---|---|---|
service | string | Name of service. |
serviceProvider | TestServiceProvider | A test service provider object. |
Box.Application.getServiceForTest('some-service', new Box.TestServiceProvider({
logger: {
warn: function() {}
}
});
Retrieves an instance of a registered module with a TestServiceProvider
object.
Parameter | Type | Description |
---|---|---|
module | string | Name of module. |
serviceProvider | TestServiceProvider | A test service provider object. |
Box.Application.getModuleForTest('some-module', new Box.TestServiceProvider({
logger: {
warn: function() {}
}
});
Retrieves an instance of a registered module with a TestServiceProvider
object.
Parameter | Type | Description |
---|---|---|
module | string | Name of module. |
serviceProvider | TestServiceProvider | A test service provider object. |
Box.Application.getModuleForTest('some-module', new Box.TestServiceProvider({
logger: {
warn: function() {}
}
});
Retrieves an instance of a registered behavior with a TestServiceProvider
object.
Parameter | Type | Description |
---|---|---|
behavior | string | Name of behavior. |
serviceProvider | TestServiceProvider | A test service provider object. |
Box.Application.getBehaviorForTest('some-behavior', new Box.TestServiceProvider({
logger: {
warn: function() {}
}
});
Unregisters all services, modules, and behaviors
Box.Application.reset();