Tôi đã tạo một ứng dụng bằng ng-table, ứng dụng này hoạt động tốt nhưng khi tôi viết một trường hợp thử nghiệm hoa nhài tôi đang nhận được.AngularJS - mocking ngTableParams trong trường hợp thử nghiệm hoa nhài
Error: [$injector:unpr] Unknown provider: TableParamsProvider
bất cứ ai có thể vui lòng cho tôi biết làm thế nào để chế nhạo các ngTableParams
và kiểm tra chức năng của nó
Mã của tôi là như đưa ra dưới đây
test nhài
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();
});
});
});
kịch bản
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'
});
});
máy trạm/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
};
});
Không có thay đổi nào cả ... thực sự ng-table được định nghĩa trong main.js ............. chúng ta là đứa trẻ, tôi đã thêm ng-route và toàn bộ kịch bản –
cũng không chỉ chế giễu tôi muốn kiểm tra chức năng asc quá –
Tôi đã chỉnh sửa câu trả lời. Bạn có ý nghĩa gì 'chức năng asc'? – kihu