首页 > 代码库 > angular 测试
angular 测试
describe(‘Controllers: CheckListOverCtrl‘, function () { var $scope, ctrl, $httpBackend; var data = http://www.mamicode.com/[];"ProjectName1", I_Category: "I_Category1", uName: "uName1", dName: "dName1", D_Create: "D_Create1" }, //{ name: ‘name2‘, ProjectName: "ProjectName2", I_Category: "I_Category2", uName: "uName2", dName: "dName2", D_Create: "D_Create2" }, { name: ‘name3‘, ProjectName: "ProjectName3", I_Category: "I_Category3", uName: "uName3", dName: "dName3", D_Create: "D_Create3" }]; beforeEach(angular.mock.module(‘app.audit‘)); beforeEach(angular.mock.inject(function ($rootScope, $controller, _$httpBackend_) { $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); ctrl = $controller(‘CheckListOverCtrl‘, { $scope: $scope }); })); it("标题测试", function () { expect($scope.$root.title).toBe(‘已审列表‘); }); it("取数据测试", function () { expect($scope.list.length).toBe(0); $httpBackend.expectPOST(‘/Services/AuditWebForm.aspx/GetCheckListOver‘).respond(data); $httpBackend.expectPOST(‘/Services/UserAuth.aspx/GetUidList‘).respond(‘‘); $httpBackend.flush(); expect($scope.list.length).toBe(2); }); it("链接测试", function () { expect($scope.gethref(1, 1, 1)).toBe(‘../projectView/flowChart?id=1&type=1‘); expect($scope.gethref(2, 1, 1)).toBe(‘../budgetView/flowChart?id=1&ProjectId=1&type=2‘); expect($scope.gethref(3, 1, 1)).toBe(‘../contractView/flowChart?id=1&ProjectId=1&type=3‘); expect($scope.gethref(4, 1, 1)).toBe(‘../ExpenseView/flowChart?id=1&ProjectId=1&type=4‘); expect($scope.gethref(5, 1, 1)).toBe(‘../ReceiptView/flowChart?id=1&ProjectId=1&type=5‘); expect($scope.gethref(6, 1, 1)).toBe(‘../WorkView/flowChart?id=1&ProjectId=1&type=6‘); }); it("type字符串测试", function () { expect($scope.typestring(1)).toBe(‘项目‘); expect($scope.typestring(2)).toBe(‘预算‘); expect($scope.typestring(3)).toBe(‘合同‘); expect($scope.typestring(4)).toBe(‘报销‘); expect($scope.typestring(5)).toBe(‘发票‘); expect($scope.typestring(6)).toBe(‘工单‘); }); it("时间字符串测试", function () { expect($scope.datestring(‘2014-10-09T 09:43:00‘)).toBe(‘2014-10-09‘); });});
controller为audit。测试getlist方法。预先留好返回值,在测试的具体方法it()内,预设expectpost ,表明flush时会按预设的expensepost走。
angular 测试
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。