bardjs
Version:
Spec helpers for testing angular v.1.x apps with Mocha, Jasmine or QUnit
8 lines • 2.11 kB
JavaScript
/**
* bardjs - Spec helpers for testing angular v.1.x apps with Mocha, Jasmine or QUnit
* @authors John Papa,Ward Bell
* @version v0.1.8
* @link https://github.com/wardbell/bardjs
* @license MIT
*/
!function(){window.bard=window.bard||{},window.bard.ngRouteTester=function(e){function t(t){function n(){p=u.document,i=angular.element(p.createElement("div")),t.value("$rootElement",i);var e=u.mockLocationPaths;if((null==e?!0:e)&&t.decorator("$location",a),u.templateUrl&&o(),u.template){i.html(u.template);var n=angular.element(i[0].querySelector(f));c=n.parent()}else c=angular.element("<div><div ng-view></div></div>"),i.append(c)}function a(e,t){var n=e.path();return e.path=function(e){return e?(n!==e&&(n=e,t.$broadcast("$locationChangeSuccess",e)),this):n},e}function o(){var e=new XMLHttpRequest;if(e.open("GET",u.templateUrl,!1),e.send(null),200!==e.status)throw new Error("ngRouteTester: Unable to download template file");u.template=e.responseText}function r(e,t,n,a){function o(){l=angular.element('<div status="{{__VIEW_STATUS}}"></div>'),i.append(l),n.$apply(function(){i.data("$injector",t),e(i)(n),angular.element(p.body).append(i)})}function r(){angular.forEach(d,function(e){clearTimeout(e)});var e=angular.element(document.body);e.removeData(),i.remove(),n.$destroy()}function u(){return t.get("$location").path()}function s(){return angular.element(c[0].querySelector(f))}function $(e,a){n.__VIEW_STATUS=++m,g(function(){return parseInt(l.attr("status"))>=m},function(){setTimeout(a||v,0)});var o=function(){t.get("$location").path(e)};n.$$phase?o():n.$apply(o)}function g(e,t){var n,a=50;n=setInterval(function(){e()&&(clearTimeout(n),t())},a),d.push(n)}return o(),afterEach&&afterEach(r),{$injector:t,$rootScope:n,$route:a,path:u,rootElement:i,until:g,viewElement:s,visit:$}}var u={document:document};angular.extend(u,e),n(),t.factory("ngRouteTester",r);var i,c,l,p,d=[],m=0,v=angular.noop,f="ng-view, [ng-view], .ng-view, [x-ng-view], [data-ng-view]";a.$inject=["$delegate","$rootScope"],r.$inject=["$compile","$injector","$rootScope","$route"]}return t.$inject=["$provide"],t}}();