jasmine_rsvp
Version:
Jasmine helpers for testing RSVP-Promise driven code.
1 lines • 19 kB
JavaScript
function has(e){var t=featureMap[e];return isFunction(proto[t])}define("rsvp/all",["./promise","exports"],function(e,t){var n=e["default"];t["default"]=function(t,r){return n.all(t,r)}}),define("rsvp/all_settled",["./promise","./utils","exports"],function(e,t,n){function o(e){return{state:"fulfilled",value:e}}function u(e){return{state:"rejected",reason:e}}var r=e["default"],i=t.isArray,s=t.isNonThenable;n["default"]=function(t,n){return new r(function(e,n){function c(e){return function(t){p(e,o(t))}}function h(e){return function(t){p(e,u(t))}}function p(t,n){l[t]=n,--a===0&&e(l)}if(!i(t))throw new TypeError("You must pass an array to allSettled.");var a=t.length,f;if(a===0){e([]);return}var l=new Array(a);for(var d=0;d<t.length;d++)f=t[d],s(f)?p(d,o(f)):r.resolve(f).then(c(d),h(d))},n)}}),define("rsvp/asap",["exports"],function(e){function r(){return function(){process.nextTick(u)}}function i(){var e=0,t=new n(u),r=document.createTextNode("");return t.observe(r,{characterData:!0}),function(){r.data=e=++e%2}}function s(){return function(){setTimeout(u,1)}}function u(){for(var e=0;e<o.length;e++){var t=o[e],n=t[0],r=t[1];n(r)}o=[]}e["default"]=function(t,n){var r=o.push([t,n]);r===1&&a()};var t=typeof window!="undefined"?window:{},n=t.MutationObserver||t.WebKitMutationObserver,o=[],a;typeof process!="undefined"&&{}.toString.call(process)==="[object process]"?a=r():n?a=i():a=s()}),define("rsvp/config",["./events","exports"],function(e,t){function i(e,t){if(e==="onerror"){r.on("error",t);return}if(arguments.length!==2)return r[e];r[e]=t}var n=e["default"],r={instrument:!1};n.mixin(r),t.config=r,t.configure=i}),define("rsvp/defer",["./promise","exports"],function(e,t){var n=e["default"];t["default"]=function(t){var r={};return r.promise=new n(function(e,t){r.resolve=e,r.reject=t},t),r}}),define("rsvp/events",["exports"],function(e){var t=function(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},n=function(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t};e["default"]={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=undefined,e},on:function(e,r){var i=n(this),s;s=i[e],s||(s=i[e]=[]),t(s,r)===-1&&s.push(r)},off:function(e,r){var i=n(this),s,o;if(!r){i[e]=[];return}s=i[e],o=t(s,r),o!==-1&&s.splice(o,1)},trigger:function(e,t){var r=n(this),i,s,o,u;if(i=r[e])for(var a=0;a<i.length;a++)o=i[a],o(t)}}}),define("rsvp/filter",["./all","./map","./utils","exports"],function(e,t,n,r){function a(e,t,n){return i(e,n).then(function(r){if(!u(e))throw new TypeError("You must pass an array to filter.");if(!o(t))throw new TypeError("You must pass a function to filter's second argument.");return s(e,t,n).then(function(e){var t,n=r.length,i=[];for(t=0;t<n;t++)e[t]&&i.push(r[t]);return i})})}var i=e["default"],s=t["default"],o=n.isFunction,u=n.isArray;r["default"]=a}),define("rsvp/hash",["./promise","./utils","exports"],function(e,t,n){var r=e["default"],i=t.isNonThenable,s=t.keysOf;n["default"]=function(t,n){return new r(function(e,n){function c(t){return function(n){o[t]=n,--a===0&&e(o)}}function h(e){a=0,n(e)}var o={},u=s(t),a=u.length,f,l;if(a===0){e(o);return}for(var p=0;p<u.length;p++)l=u[p],f=t[l],i(f)?(o[l]=f,--a===0&&e(o)):r.resolve(f).then(c(l),h)})}}),define("rsvp/hash_settled",["./promise","./utils","exports"],function(e,t,n){function o(e){return{state:"fulfilled",value:e}}function u(e){return{state:"rejected",reason:e}}var r=e["default"],i=t.isNonThenable,s=t.keysOf;n["default"]=function(t,n){return new r(function(e,n){function p(e){return function(t){v(e,o(t))}}function d(e){return function(t){v(e,u(t))}}function v(t,n){a[t]=n,--l===0&&e(a)}var a={},f=s(t),l=f.length,c,h;if(l===0){e(a);return}for(var m=0;m<f.length;m++)h=f[m],c=t[h],i(c)?v(h,o(c)):r.resolve(c).then(p(h),d(h))})}}),define("rsvp/instrument",["./config","./utils","exports"],function(e,t,n){var r=e.config,i=t.now;n["default"]=function(t,n,s){try{r.trigger(t,{guid:n._guidKey+n._id,eventName:t,detail:n._detail,childGuid:s&&n._guidKey+s._id,label:n._label,timeStamp:i(),stack:(new Error(n._label)).stack})}catch(o){setTimeout(function(){throw o},0)}}}),define("rsvp/map",["./promise","./utils","exports"],function(e,t,n){var r=e["default"],i=t.isArray,s=t.isFunction;n["default"]=function(t,n,o){return r.all(t,o).then(function(e){if(!i(t))throw new TypeError("You must pass an array to map.");if(!s(n))throw new TypeError("You must pass a function to map's second argument.");var u=e.length,a=[],f;for(f=0;f<u;f++)a.push(n(e[f]));return r.all(a,o)})}}),define("rsvp/node",["./promise","./utils","exports"],function(e,t,n){var r=e["default"],i=t.isArray;n["default"]=function(t,n){return function(){var e=arguments.length,s=new Array(e);for(var o=0;o<e;o++)s[o]=arguments[o];var u=n===!0,a=i(n),f;return!u&&!a&&n?(console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),f=n):f=this,r.all(s).then(function(e){function i(r,i){function s(){var e=arguments.length,t=new Array(e);for(var s=0;s<e;s++)t[s]=arguments[s];var o=t[0],f=t[1];if(o)i(o);else if(u)r(t.slice(1));else if(a){var l={},c=t.slice(1),h,p;for(p=0;p<n.length;p++)h=n[p],l[h]=c[p];r(l)}else r(f)}e.push(s),t.apply(f,e)}return new r(i)})}}}),define("rsvp/promise",["./config","./events","./instrument","./utils","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(e,t,n,r,i,s,o,u,a,f){function x(){}function T(e,t){if(!d(e))throw new TypeError("You must pass a resolver function as the first argument to the promise constructor");if(!(this instanceof T))throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");this._id=S++,this._label=t,this._subscribers=[],l.instrument&&h("created",this),x!==e&&N(e,this)}function N(e,t){function n(e){P(t,e)}function r(e){B(t,e)}try{e(n,r)}catch(i){r(i)}}function O(e,t,n,r){var i=e._subscribers,s=i.length;i[s]=t,i[s+L]=n,i[s+A]=r}function M(e,t){var n,r,i=e._subscribers,s=e._detail;l.instrument&&h(t===L?"fulfilled":"rejected",e);for(var o=0;o<i.length;o+=3)n=i[o],r=i[o+t],_(t,n,r,s);e._subscribers=null}function _(e,t,n,r){var i=d(n),s,o,u,a;if(i)try{s=n(r),u=!0}catch(f){a=!0,o=f}else s=r,u=!0;if(D(t,s))return;i&&u?P(t,s):a?B(t,o):e===L?P(t,s):e===A&&B(t,s)}function D(e,t){var n=null,r;try{if(e===t)throw new TypeError("A promises callback cannot return that same promise.");if(p(t)){n=t.then;if(d(n))return n.call(t,function(n){if(r)return!0;r=!0,t!==n?P(e,n):H(e,n)},function(t){if(r)return!0;r=!0,B(e,t)},"Settle: "+(e._label||" unknown promise")),!0}}catch(i){return r?!0:(B(e,i),!0)}return!1}function P(e,t){e===t?H(e,t):D(e,t)||H(e,t)}function H(e,t){if(e._state!==C)return;e._state=k,e._detail=t,l.async(j,e)}function B(e,t){if(e._state!==C)return;e._state=k,e._detail=t,l.async(F,e)}function j(e){M(e,e._state=L)}function F(e){e._onerror&&e._onerror(e._detail),M(e,e._state=A)}var l=e.config,c=t["default"],h=n["default"],p=r.objectOrFunction,d=r.isFunction,v=r.now,m=i["default"],g=s["default"],y=o["default"],b=u["default"],w=a["default"],E="rsvp_"+v()+"-",S=0;f["default"]=T,T.cast=m,T.all=g,T.race=y,T.resolve=b,T.reject=w;var C=void 0,k=0,L=1,A=2;T.prototype={constructor:T,_id:undefined,_guidKey:E,_label:undefined,_state:undefined,_detail:undefined,_subscribers:undefined,_onerror:function(e){l.trigger("error",e)},then:function(e,t,n){var r=this;this._onerror=null;var i=new this.constructor(x,n);if(this._state){var s=arguments;l.async(function(){_(r._state,i,s[r._state-1],r._detail)})}else O(this,i,e,t);return l.instrument&&h("chained",r,i),i},"catch":function(e,t){return this.then(null,e,t)},"finally":function(e,t){var n=this.constructor;return this.then(function(t){return n.cast(e()).then(function(){return t})},function(t){return n.cast(e()).then(function(){throw t})},t)}}}),define("rsvp/promise/all",["../utils","exports"],function(e,t){var n=e.isArray,r=e.isNonThenable;t["default"]=function(t,i){var s=this;return new s(function(e,i){function l(t){return function(n){u[t]=n,--o===0&&e(u)}}function c(e){o=0,i(e)}if(!n(t))throw new TypeError("You must pass an array to all.");var o=t.length,u=new Array(o),a,f=!0;if(o===0){e(u);return}for(var h=0;h<t.length;h++)a=t[h],r(a)?(u[h]=a,--o===0&&e(u)):s.resolve(a).then(l(h),c)},i)}}),define("rsvp/promise/cast",["exports"],function(e){e["default"]=function(t,n){var r=this;return t&&typeof t=="object"&&t.constructor===r?t:new r(function(e){e(t)},n)}}),define("rsvp/promise/race",["../utils","exports"],function(e,t){var n=e.isArray,r=e.isFunction,i=e.isNonThenable;t["default"]=function(t,r){var s=this,o;return new s(function(e,r){function a(t){u&&(u=!1,e(t))}function f(e){u&&(u=!1,r(e))}if(!n(t))throw new TypeError("You must pass an array to race.");var u=!0;for(var l=0;l<t.length;l++){o=t[l];if(i(o)){u=!1,e(o);return}s.resolve(o).then(a,f)}},r)}}),define("rsvp/promise/reject",["exports"],function(e){e["default"]=function(t,n){var r=this;return new r(function(e,n){n(t)},n)}}),define("rsvp/promise/resolve",["exports"],function(e){e["default"]=function(t,n){var r=this;return t&&typeof t=="object"&&t.constructor===r?t:new r(function(e){e(t)},n)}}),define("rsvp/race",["./promise","exports"],function(e,t){var n=e["default"];t["default"]=function(t,r){return n.race(t,r)}}),define("rsvp/reject",["./promise","exports"],function(e,t){var n=e["default"];t["default"]=function(t,r){return n.reject(t,r)}}),define("rsvp/resolve",["./promise","exports"],function(e,t){var n=e["default"];t["default"]=function(t,r){return n.resolve(t,r)}}),define("rsvp/rethrow",["exports"],function(e){e["default"]=function(t){throw setTimeout(function(){throw t}),t}}),define("rsvp/utils",["exports"],function(e){function t(e){return typeof e=="function"||typeof e=="object"&&e!==null}function n(e){return typeof e=="function"}function r(e){return!t(e)}e.objectOrFunction=t,e.isFunction=n,e.isNonThenable=r;var i;Array.isArray?i=Array.isArray:i=function(e){return Object.prototype.toString.call(e)==="[object Array]"};var s=i;e.isArray=s;var o=Date.now||function(){return(new Date).getTime()};e.now=o;var u=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};e.keysOf=u}),define("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all_settled","./rsvp/race","./rsvp/hash","./rsvp/hash_settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(e,t,n,r,i,s,o,u,a,f,l,c,h,p,d,v,m){function P(e,t){k.async(e,t)}function H(){k.on.apply(k,arguments)}function B(){k.off.apply(k,arguments)}var g=e["default"],y=t["default"],b=n["default"],w=r["default"],E=i["default"],S=s["default"],x=o["default"],T=u["default"],N=a["default"],C=f["default"],k=l.config,L=l.configure,A=c["default"],O=h["default"],M=p["default"],_=d["default"],D=v["default"];k.async=D;if(typeof window!="undefined"&&typeof window.__PROMISE_INSTRUMENTATION__=="object"){var j=window.__PROMISE_INSTRUMENTATION__;L("instrument",!0);for(var F in j)j.hasOwnProperty(F)&&H(F,j[F])}m.Promise=g,m.EventTarget=y,m.all=w,m.allSettled=E,m.race=S,m.hash=x,m.hashSettled=T,m.rethrow=N,m.defer=C,m.denodeify=b,m.configure=L,m.on=H,m.off=B,m.resolve=O,m.reject=M,m.async=P,m.map=A,m.filter=_});var isFunction=function(e){return typeof e=="function"},bind,slice=[].slice,proto=Function.prototype,featureMap;featureMap={"function-bind":"bind"},has("function-bind")||(bind=function(t){var n=slice.call(arguments,1),r=this,i=function(){},s=function(){return r.apply(this instanceof i?this:t||{},n.concat(slice.call(arguments)))};return i.prototype=this.prototype||{},s.prototype=new i,s},proto.bind=bind),define("jasmine_rsvp/phantomjs_polyfills",function(){}),define("backburner/queue",["exports"],function(e){function t(e,t,n){this.daq=e,this.name=t,this.options=n,this._queue=[]}t.prototype={daq:null,name:null,options:null,_queue:null,push:function(e,t,n,r){var i=this._queue;return i.push(e,t,n,r),{queue:this,target:e,method:t}},pushUnique:function(e,t,n,r){var i=this._queue,s,o,u,a;for(u=0,a=i.length;u<a;u+=4){s=i[u],o=i[u+1];if(s===e&&o===t)return i[u+2]=n,i[u+3]=r,{queue:this,target:e,method:t}}return this._queue.push(e,t,n,r),{queue:this,target:e,method:t}},flush:function(){var e=this._queue,t=this.options,n=t&&t.before,r=t&&t.after,i,s,o,u,a,f=e.length;f&&n&&n();for(a=0;a<f;a+=4)i=e[a],s=e[a+1],o=e[a+2],u=e[a+3],o&&o.length>0?s.apply(i,o):s.call(i);f&&r&&r(),e.length>f?(this._queue=e.slice(f),this.flush()):this._queue.length=0},cancel:function(e){var t=this._queue,n,r,i,s;for(i=0,s=t.length;i<s;i+=4){n=t[i],r=t[i+1];if(n===e.target&&r===e.method)return t.splice(i,4),!0}t=this._queueBeingFlushed;if(!t)return;for(i=0,s=t.length;i<s;i+=4){n=t[i],r=t[i+1];if(n===e.target&&r===e.method)return t[i+1]=null,!0}}},e.Queue=t}),define("backburner/deferred_action_queues",["backburner/queue","exports"],function(e,t){function r(e,t){var r=this.queues={};this.queueNames=e=e||[];var i;for(var s=0,o=e.length;s<o;s++)i=e[s],r[i]=new n(this,i,t[i])}function i(e,t){var n,r;for(var i=0,s=t;i<=s;i++){n=e.queueNames[i],r=e.queues[n];if(r._queue.length)return i}return-1}var n=e.Queue;r.prototype={queueNames:null,queues:null,schedule:function(e,t,n,r,i,s){var o=this.queues,u=o[e];if(!u)throw new Error("You attempted to schedule an action in a queue ("+e+") that doesn't exist");return i?u.pushUnique(t,n,r,s):u.push(t,n,r,s)},flush:function(){var e=this.queues,t=this.queueNames,n,r,s,o,u=0,a=t.length;e:while(u<a){n=t[u],r=e[n],s=r._queueBeingFlushed=r._queue.slice(),r._queue=[];var f=r.options,l=f&&f.before,c=f&&f.after,h,p,d,v,m=0,g=s.length;g&&l&&l();while(m<g)h=s[m],p=s[m+1],d=s[m+2],v=s[m+3],typeof p=="string"&&(p=h[p]),p&&(d&&d.length>0?p.apply(h,d):p.call(h)),m+=4;r._queueBeingFlushed=null,g&&c&&c();if((o=i(this,u))!==-1){u=o;continue e}u++}}},t.DeferredActionQueues=r}),define("backburner",["backburner/deferred_action_queues","exports"],function(e,t){function p(e){return typeof e=="number"||h.test(e)}function d(e,t){this.queueNames=e,this.options=t||{},this.options.defaultQueue||(this.options.defaultQueue=e[0]),this.instanceStack=[]}function v(e){e.begin(),a=c.setTimeout(function(){a=null,e.end()})}function m(e){var t=+(new Date),n,r,i,s;e.run(function(){for(i=0,s=u.length;i<s;i+=2){n=u[i];if(n>t)break}r=u.splice(0,i);for(i=1,s=r.length;i<s;i+=2)e.schedule(e.options.defaultQueue,null,r[i])}),u.length&&(f=c.setTimeout(function(){m(e),f=null,l=null},u[0]-t),l=u[0])}function g(e,t){var n,r=-1;for(var i=0,s=o.length;i<s;i++){n=o[i];if(n[0]===e&&n[1]===t){r=i;break}}return r}var n=e.DeferredActionQueues,r=[].slice,i=[].pop,s=[],o=[],u=[],a,f,l,c=this,h=/\d+/;d.prototype={queueNames:null,options:null,currentInstance:null,instanceStack:null,begin:function(){var e=this.options&&this.options.onBegin,t=this.currentInstance;t&&this.instanceStack.push(t),this.currentInstance=new n(this.queueNames,this.options),e&&e(this.currentInstance,t)},end:function(){var e=this.options&&this.options.onEnd,t=this.currentInstance,n=null;try{t.flush()}finally{this.currentInstance=null,this.instanceStack.length&&(n=this.instanceStack.pop(),this.currentInstance=n),e&&e(t,n)}},run:function(e,t){var n;this.begin(),t||(t=e,e=null),typeof t=="string"&&(t=e[t]);var i=!1;try{arguments.length>2?n=t.apply(e,r.call(arguments,2)):n=t.call(e)}finally{i||(i=!0,this.end())}return n},defer:function(e,t,n){n||(n=t,t=null),typeof n=="string"&&(n=t[n]);var i=this.DEBUG?(new Error).stack:undefined,s=arguments.length>3?r.call(arguments,3):undefined;return this.currentInstance||v(this),this.currentInstance.schedule(e,t,n,s,!1,i)},deferOnce:function(e,t,n){n||(n=t,t=null),typeof n=="string"&&(n=t[n]);var i=this.DEBUG?(new Error).stack:undefined,s=arguments.length>3?r.call(arguments,3):undefined;return this.currentInstance||v(this),this.currentInstance.schedule(e,t,n,s,!0,i)},setTimeout:function(){function y(){n.apply(s,e)}var e=r.call(arguments),t=e.length,n,i,s,o=this,a,h,d;if(t===0)return;if(t===1)n=e.shift(),i=0;else if(t===2)a=e[0],h=e[1],typeof h=="function"||typeof a[h]=="function"?(s=e.shift(),n=e.shift(),i=0):p(h)?(n=e.shift(),i=e.shift()):(n=e.shift(),i=0);else{var v=e[e.length-1];p(v)&&(i=e.pop()),a=e[0],d=e[1],typeof d=="function"||typeof d=="string"&&a!==null&&d in a?(s=e.shift(),n=e.shift()):n=e.shift()}var g=+(new Date)+parseInt(i,10);typeof n=="string"&&(n=s[n]);var b,w;for(b=0,w=u.length;b<w;b+=2)if(g<u[b])break;return u.splice(b,0,g,y),f&&l<g?y:(f&&(clearTimeout(f),f=null),f=c.setTimeout(function(){m(o),f=null,l=null},i),l=g,y)},throttle:function(e,t){var n=this,r=arguments,o=parseInt(i.call(r),10),u;for(var a=0,f=s.length;a<f;a++){u=s[a];if(u[0]===e&&u[1]===t)return}var l=c.setTimeout(function(){n.run.apply(n,r);var i=-1;for(var o=0,a=s.length;o<a;o++){u=s[o];if(u[0]===e&&u[1]===t){i=o;break}}i>-1&&s.splice(i,1)},o);s.push([e,t,l])},debounce:function(e,t){var n=this,r=arguments,s=i.call(r),u,a,f;typeof s=="number"||typeof s=="string"?(u=s,s=!1):u=i.call(r),u=parseInt(u,10),a=g(e,t),a!==-1&&(f=o[a],o.splice(a,1),clearTimeout(f[2]));var l=c.setTimeout(function(){s||n.run.apply(n,r),a=g(e,t),a&&o.splice(a,1)},u);s&&a===-1&&n.run.apply(n,r),o.push([e,t,l])},cancelTimers:function(){var e,t;for(e=0,t=s.length;e<t;e++)clearTimeout(s[e][2]);s=[];for(e=0,t=o.length;e<t;e++)clearTimeout(o[e][2]);o=[],f&&(clearTimeout(f),f=null),u=[],a&&(clearTimeout(a),a=null)},hasTimers:function(){return!!u.length||a},cancel:function(e){if(e&&typeof e=="object"&&e.queue&&e.method)return e.queue.cancel(e);if(typeof e!="function")return;for(var t=0,n=u.length;t<n;t+=2)if(u[t+1]===e)return u.splice(t,2),!0}},d.prototype.schedule=d.prototype.defer,d.prototype.scheduleOnce=d.prototype.deferOnce,d.prototype.later=d.prototype.setTimeout,t.Backburner=d}),define("jasmine_rsvp/promise_suite",["require","rsvp","backburner"],function(e){function s(e,t){i.defer("promises",t,e,t)}function o(){i.end(),i.begin()}function u(){r=t.configure("async"),t.configure("async",s),i.begin(),a(this)}function a(e){e.flush=function(){o()}}function f(){t.configure("async",r)}var t=e("rsvp"),n=e("backburner"),r,i=new n.Backburner(["promises"]),l=function(e){return e.__promiseSuiteSetup=!0,e.beforeEach(function(){u.call(this)}),e.afterEach(f),this};return function(){if(this.__promiseSuiteSetup)return;l(this)}}),define("jasmine_rsvp/main",["require","rsvp","./phantomjs_polyfills","./promise_suite"],function(e){var t=e("rsvp"),n=e("./phantomjs_polyfills"),r=e("./promise_suite"),i=jasmine.Suite,s=jasmine.RSVP={enabled:!0,logRSVPErrors:!0};return t.configure("onerror",function(e){if(!s.logRSVPErrors)return;console.error("RSVP error:",e),e&&e.message&&console.error(e.message),e&&e.stack&&console.error(e.stack)}),Object.defineProperty(i.prototype,"promiseSuite",{set:function(){r.call(this)}}),s}),define("jasmine_rsvp",["jasmine_rsvp/main"],function(e){return e});