我不确定如何测试 routeProvider 解析的结果。
在路由提供程序中我如何调用某些东西。
我如何测试返回结果是否符合我的预期。
在以下示例中,这就是我所缺少的:
假设我有以下路由提供程序配置:
var rt = angular.module("ResolveTest",[]);
rt.config(["$routeProvider",function($routeProvider)
{
$routeProvider.when("/",{
templateUrl: "rt.html",
controller: "ResolveCtrl",
resolve: {
data: ["$q","$timeout",function($q,$timeout)
{
var deferred = $q.defer();
$timeout(function()
{
deferred.resolve("my data value");
},2000);
return deferred.promise;
}]
}
});
}]);
这是 spec.js 文件:
describe("Testing route provide resolve", function() {
var routes;
it('should test routeProvider', function() {
inject(function($route, $location, $rootScope) {
routes = $route;
});
// here I would like to check that my data value was resolved from the route.
// how can i do that?
});
有人可以给出一个完整的工作示例来说明如何调用正确的路线并测试解决方案吗?