大佬教程收集整理的这篇文章主要介绍了angularjs – 使用模拟的httpBackend进行角度E2E测试?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
所以,在我们的index.html中
if (document.LOCATIOn.hash === '#test') { addScript('/test/lib/angular-mocks.js'); addScript('/test/e2e/ourTest.js'); window.fixtures = {}; addScript('/test/fixtures/tasks/tasks_p1.js'); // the tasks_p1.js is generated and has "window.fixtures.tasks_p1 = ...json..." addScript('/test/fixtures/tasks/tasks_p2.js'); // the tasks_p2.js is generated and has "window.fixtures.tasks_p2 = ...json..." addScript('/test/e2e/tasks/taskmocks.js\'><\/script>'); }
ourTest.js
angular.module('ourTestApp',['ngmockE2E','taskmocks']). run(function ($httpBACkend,taskmocks) { $httpBACkend.whenGET(/views\/.*/).passThrough(); $httpBACkend.whenGET(/\/fixtures.*\//).passThrough(); taskmocks.register(); $httpBACkend.whenGET(/.*/).passThrough(); });
/*global angular */ angular.module('taskmocks',['ngmockE2E']). factory('taskmocks',['$httpBACkend',function($httpBACkend) { 'use Strict'; return { register: function() { $httpBACkend.whenGET(..regex_for_url_for_page1..).respond(window.fixtures.tasks_p1); $httpBACkend.whenGET(..regex_for_url_for_page2..).respond(window.fixtures.tasks_p2); } }; }]);
在少数情况下,我们的数据与当前日期有关;例如“本周的任务”,所以我们在register()方法中按下捕获的数据.
编辑
我们现在使用Rosie为我们的模拟对象创建工厂.因此,没有更多的CURLing测试服务器用于预期的json响应. index.html不再加载这些“.js”灯具,模拟看起来像:
/*global angular */ angular.module('taskmocks',function($httpBACkend) { 'use Strict'; var tasks_p1 = [ Factory.build('task'),Factory.build('task')],tasks_p2 = [ Factory.build('task'),Factory.build('task')] return { register: function() { $httpBACkend.whenGET(..regex_for_url_for_page1..).respond(tasks_p1); $httpBACkend.whenGET(..regex_for_url_for_page2..).respond(tasks_p2); } }; }]);
以上是大佬教程为你收集整理的angularjs – 使用模拟的httpBackend进行角度E2E测试?全部内容,希望文章能够帮你解决angularjs – 使用模拟的httpBackend进行角度E2E测试?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。