【发布时间】:2013-01-24 04:10:39
【问题描述】:
有没有人提供如何对提供程序进行单元测试的示例?
例如:
config.js
angular.module('app.config', [])
.provider('config', function () {
var config = {
mode: 'distributed',
api: 'path/to/api'
};
this.mode = function (type) {
if (type) {
config.isDistributedInstance = type === config.mode;
config.isLocalInstance = !config.isDistributedInstance;
config.mode = type;
return this;
} else {
return config.mode;
}
};
this.$get = function () {
return config;
};
}]);
app.js
angular.module('app', ['app.config'])
.config(['configProvider', function (configProvider) {
configProvider.mode('local');
}]);
app.js 正在测试中使用,我看到已经配置了configProvider,我可以将其作为服务进行测试。但是如何测试配置能力呢?还是根本不需要?
【问题讨论】:
标签: unit-testing angularjs jasmine