ngTableParams我一直在使用NG表创建的应用程序,该应用程序是workign正常,但当我写了一个茉莉花测试情况下,我得到。AngularJS - 嘲讽茉莉测试用例
Error: [$injector:unpr] Unknown provider: TableParamsProvider
谁能告诉我如何嘲笑ngTableParams
并测试其功能
我的代码如下
茉莉测试用例
describe('Testing Controllers', function() {
describe('Testing WorkController Controller', function() {
var WorkController, $scope;
beforeEach(module('wsd.workstations'));
beforeEach(inject(function($controller, $rootScope) {
$scope = $rootScope.$new();
WorkController = $controller('WorkController', {
$rootScope: $rootScope,
$scope: $scope
});
}));
it('should searchDocuments when searchDocuments() is called', function() {
$scope.searchDocuments();
});
});
});
脚本给出
angular.module('wsd', ['restangular', 'ngTable', 'wsd.models', 'wsd.workstations', 'wsd.workperiods', 'ngRoute'])
.config(function(RestangularProvider, $routeProvider) {
RestangularProvider.setBaseUrl('/rest/myuser');
$routeProvider.when('/wd', {
templateUrl: 'main/workstation/main.tpl.html',
controller: 'WorkController',
resolve: {
myWorkDocuments: function(Documents) {
return Documents.getWorkDocuments();
}
}
}).when('/wp', {
templateUrl: 'main/workperiod/main.tpl.html',
controller: 'PeriodController',
resolve: {
myWorkPeriods: function(Periods) {
return Periods.getWorkPeriods();
}
}
}).otherwise({
redirectTo: '/wd'
});
});
工作站/ main.js
angular.module('wsd.workstations', [])
.controller('WorkController', function($rootScope, $scope, $filter, ngTableParams)
{
$scope.myValues = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];
$scope.tableParams = new ngTableParams({
sorting: {
name: 'asc'
}
}, {
getData: function($defer, params) {
$scope.myValues = $filter('orderBy')($scope.myValues, params.orderBy());
$defer.resolve($scope.myValues);
}
});
$scope.searchDocuments = function()
{
// some other logic
};
});
没有一分钟的变化....实际上ng-table是在main.js中定义的...............我们是那个孩子,我已经添加了ng路由和完整的脚本 – 2014-10-10 13:23:02
也不仅嘲笑我想测试的ASC功能 – 2014-10-10 13:37:38
我编辑了答案。你的意思是'asc功能'? – kihu 2014-10-10 13:45:50