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