Comparing version 0.2.2 to 0.2.3
@@ -1,1 +0,1 @@ | ||
var A=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var P=(t,e)=>{var n={};for(var r in t)w.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&A)for(var r of A(t))e.indexOf(r)<0&&j.call(t,r)&&(n[r]=t[r]);return n};function u(t,e){if(!t)throw new Error(e)}function i(t,e){return typeof e===t}var f=new Set;function b(t){u(i("function",t)||i("undefined",t),"cannot spy on a non-function value");let e=function(...r){if(e.called=!0,e.callCount++,e.calls.push(r),e.next){let[p,c]=e.next;if(e.results.push(e.next),e.next=null,p==="ok")return c;throw c}let s,l="ok";if(e.impl)try{s=e.impl.apply(this,r),l="ok"}catch(p){s=p,l="error"}let y=[l,s];return s&&i("object",s)&&i("function",s.then)&&s.then(p=>y[1]=p),e.results.push(y),s};Object.defineProperty(e,"length",{value:t?t.length:0}),Object.defineProperty(e,"__isSpy",{value:!0}),Object.defineProperty(e,"returns",{get(){return this.results.map(([,r])=>r)}}),Object.defineProperty(e,"name",{value:t&&t.name||"spy"});let n=()=>{e.called=!1,e.callCount=0,e.results=[],e.calls=[]};return n(),e.impl=t,e.reset=n,e.nextError=r=>(e.next=["error",r],e),e.nextResult=r=>(e.next=["ok",r],e),e}var k=(t,e)=>Object.getOwnPropertyDescriptor(t,e);function $(t,e,n){u(!i("undefined",t),"spyOn could not find an object to spy upon"),u(i("object",t)||i("function",t),"cannot spyOn on a primitive value");let r=()=>typeof e=="string"?[e,"value"]:"getter"in e?[e.getter,"get"]:[e.setter,"set"],[s,l]=r(),y=k(t,s),p=Object.getPrototypeOf(t),c=p&&k(p,s),a=y||c;u(a,`${s} does not exist`),u(a.configurable,`${s} is not declared configurable`);let R=!1;l==="value"&&!a.value&&a.get&&(l="get",R=!0,n=a.get());let d=a[l];n||(n=d);let o=b(n.bind(t)),h=m=>{let v=a,{value:F}=v,T=P(v,["value"]);l!=="value"&&delete T.writable,T[l]=m,Object.defineProperty(y?t:p,s,T)},K=()=>h(d);o.restore=K,o.getOriginal=()=>R?d():d,o.willCall=m=>(o.impl=m.bind(t),o);let O=n.name||"spy",S="bound ";return n.name.startsWith(S)&&(O=n.name.slice(S.length)),Object.defineProperty(o,"name",{value:O}),h(R?()=>o:o),f.add(o),o}function z(){for(let t of f)t.restore();f.clear()}export{z as restoreAll,f as spies,b as spy,$ as spyOn}; | ||
var A=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var P=(t,e)=>{var n={};for(var r in t)K.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&A)for(var r of A(t))e.indexOf(r)<0&&w.call(t,r)&&(n[r]=t[r]);return n};function u(t,e){if(!t)throw new Error(e)}function i(t,e){return typeof e===t}var f=new Set;function b(t){u(i("function",t)||i("undefined",t),"cannot spy on a non-function value");let e=function(...r){if(e.called=!0,e.callCount++,e.calls.push(r),e.next){let[p,c]=e.next;if(e.results.push(e.next),e.next=null,p==="ok")return c;throw c}let s,l="ok";if(e.impl)try{s=e.impl.apply(this,r),l="ok"}catch(p){s=p,l="error"}let y=[l,s];return s&&i("object",s)&&i("function",s.then)&&s.then(p=>y[1]=p),e.results.push(y),s};Object.defineProperty(e,"length",{value:t?t.length:0}),Object.defineProperty(e,"__isSpy",{value:!0}),Object.defineProperty(e,"returns",{get(){return this.results.map(([,r])=>r)}}),Object.defineProperty(e,"name",{value:t&&t.name||"spy"});let n=()=>{e.called=!1,e.callCount=0,e.results=[],e.calls=[]};return n(),e.impl=t,e.reset=n,e.nextError=r=>(e.next=["error",r],e),e.nextResult=r=>(e.next=["ok",r],e),e}var k=(t,e)=>Object.getOwnPropertyDescriptor(t,e);function $(t,e,n){u(!i("undefined",t),"spyOn could not find an object to spy upon"),u(i("object",t)||i("function",t),"cannot spyOn on a primitive value");let r=()=>typeof e=="string"?[e,"value"]:"getter"in e?[e.getter,"get"]:[e.setter,"set"],[s,l]=r(),y=k(t,s),p=Object.getPrototypeOf(t),c=p&&k(p,s),a=y||c;u(a,`${s} does not exist`),u(a.configurable,`${s} is not declared configurable`);let R=!1;l==="value"&&!a.value&&a.get&&(l="get",R=!0,n=a.get());let d=a[l];n||(n=d);let o=b(n),h=m=>{let v=a,{value:F}=v,T=P(v,["value"]);l!=="value"&&delete T.writable,T[l]=m,Object.defineProperty(y?t:p,s,T)},j=()=>h(d);o.restore=j,o.getOriginal=()=>R?d():d,o.willCall=m=>(o.impl=m,o);let O=n.name||"spy",S="bound ";return n.name.startsWith(S)&&(O=n.name.slice(S.length)),Object.defineProperty(o,"name",{value:O}),h(R?()=>o:o),f.add(o),o}function z(){for(let t of f)t.restore();f.clear()}export{z as restoreAll,f as spies,b as spy,$ as spyOn}; |
{ | ||
"name": "tinyspy", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4741