[英]Mocha Chai test case for angular configuration file
我很难解决角度js配置文件的mocha chai测试用例。
angular.module('myApp.myModule', []).config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('myModule', {
url: '/myModule',
templateUrl: function(){
return 'scripts/my-module/views/my-module.html';
},
controller: 'myModuleCtrl',
controllerAs: 'myCtrl',
css: 'styles/lazy-load/my-module.css'
});
$urlRouterProvider.otherwise('/');
})
我需要为“templateUrl”的返回功能覆盖mocha chai测试用例,该模板返回一个url('scripts / my-module / views / my-module.html')。
你可以做的是在你的测试中注入$location
和$route
服务。 设置whenGET来拦截实际请求,然后在转换完成后检查$location
和$route
配置。 我之前做过类似的事
it("should load the page.", inject(function ($rootScope, $location, $route, $httpBackend) {
$httpBackend.whenGET("scripts/my-module/views/my-module.html").respond("<div/>");
$location.path("/myModule");
$rootScope.$digest();
expect($location.path()).toBe("/myModule");
}));
我使用$route
服务你需要$state
服务。
我做到了
it('should load the page.', inject(function ($state) {
var state = $state.get('selectLine');
assert.isDefined(state.templateUrl());
expect(state.templateUrl()).to.equal('scripts/select-line-module/views/select-line.html');
}));
这适合我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.