标签:服务 hid play stl exp function lan open ted
条件与目标:
实践方法:
angular.module(‘mocktest‘,[‘ngMockE2E‘]).run(function($httpBackend){ var http=$httpBackend; //pass http.whenGET(/ *.html/).passThrough(); http.whenGET(/ *.js/).passThrough(); http.whenGET(/ *.css/).passThrough(); http.whenGET(/ *.jpg/).passThrough(); //testlogin http.whenPOST(APPURL+‘/service/user/login‘).respond(function(m,url,data){ var param = angular.fromJson(data); var ret = {"result":-1,"message":"测试密码错误"}; } return [200,ret]; }); });
angular.module(‘mocktest‘).run(function($httpBackend){ var http=$httpBackend; //test http.whenPOST(new RegExp(APPURL+‘/service/user/add‘)).respond(function(m,url,data){ var ret = {"result":0,"message":""}; return [200,ret]; }); });
<script src="testapi/mockinit.js"></script> <script src="testapi/moduleusermock.js"></script> <script src="testapi/modulexxxmock.js"></script>
angular.module(‘mocktest‘,[]);
结论:
虽然不知此方法是否为违背mock的初衷,但确实在独立开发与独立测试中取得较好的效果,非AngularJS工程可参考 Mockjax。
WebUI实践之使用AngularJS 进行独立开发(模拟后台)
标签:服务 hid play stl exp function lan open ted
原文地址:http://www.cnblogs.com/coder-fang/p/6181867.html