The TestServiceProvider is meant to be a substitute for the traditional context
and application
that T3 Modules/Behaviors/Services usually have access to.
The object allows for easy stubbing of T3 services and can enable unit tests to use the real service, if necessary.
Parameter | Type | Description |
---|---|---|
serviceStubs | Object | A map of service names to stubs. |
allowedServices | string[] | List of real services to use. You must include the service in your test script. |
var context = new Box.TestServiceProvider({
logger: {
warn: function() {}
}
});
var module = Box.Application.getModuleForTest('foo', context);
var context = new Box.TestServiceProvider({}, ['logger'] );
var module = Box.Application.getModuleForTest('bar', context);
Retrieves either a service stub or the real service.
A service object or throws an error if service does not exist.
var context = new Box.TestServiceProvider({
logger: {
warn: function() {}
}
});
var loggerService = context.getService('logger');
Checks if a service stub or the real service exists
True if the service exists. False otherwise.
var context = new Box.TestServiceProvider({
logger: {
warn: function() {}
}
});
// True
context.hasService('logger');
// False
context.hasService('notifications');
Returns a global variable.
A global variable or null.
var context = new Box.TestServiceProvider({});
// Returns the window object
context.getGlobal('window');