Comparing version 0.0.15 to 0.1.0
@@ -19,3 +19,3 @@ declare let spies: Set<SpyImpl<any[], any>>; | ||
interface SpyImpl<A extends any[] = any[], R = any> extends Spy<A, R> { | ||
getOriginal: () => (...args: A) => R; | ||
getOriginal(): (...args: A) => R; | ||
willCall(cb: (...args: A) => R): this; | ||
@@ -22,0 +22,0 @@ restore(): void; |
@@ -1,1 +0,1 @@ | ||
var S=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var O=(t,e)=>{var n={};for(var r in t)b.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&S)for(var r of S(t))e.indexOf(r)<0&&K.call(t,r)&&(n[r]=t[r]);return n};function p(t,e){if(!t)throw new Error(e)}function y(t,e){return typeof e===t}var f=new Set;function v(t){p(y("function",t)||y("undefined",t),"cannot spy on a non-function value");let e=(...r)=>{if(e.called=!0,e.callCount+=1,e.calls.push(r),e.next){let[a,u]=e.next;if(e.results.push(e.next),e.next=null,a==="ok")return u;throw u}let s,o="ok";if(e.impl)try{s=e.impl(...r),o="ok"}catch(a){s=a,o="error"}return e.results.push([o,s]),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)}});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 h=(t,e)=>Object.getOwnPropertyDescriptor(t,e);function E(t,e,n){p(!y("undefined",t),"spyOn could not find an object to spy upon"),p(y("object",t)||y("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,o]=r(),a=h(t,s),u=Object.getPrototypeOf(t),k=h(u,s),i=a||k;p(i,`${s} does not exist`),p(i.configurable,`${s} is not declared configurable`);let T=!1;o==="value"&&!i.value&&i.get&&(o="get",T=!0,n=i.get());let x=i[o];n||(n=x);let l=v(n.bind(t)),m=g=>{let A=i,{value:w}=A,R=O(A,["value"]);o!=="value"&&delete R.writable,R[o]=g,Object.defineProperty(a?t:u,s,R)},F=()=>m(x);return l.restore=F,l.getOriginal=()=>x,l.willCall=g=>(l.impl=g.bind(t),l),m(T?()=>l:l),f.add(l),l}function q(){for(let t of f)t.restore();f.clear()}export{q as restoreAll,f as spies,v as spy,E as spyOn}; | ||
var O=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var v=(t,e)=>{var s={};for(var n in t)b.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(t!=null&&O)for(var n of O(t))e.indexOf(n)<0&&K.call(t,n)&&(s[n]=t[n]);return s};function u(t,e){if(!t)throw new Error(e)}function i(t,e){return typeof e===t}var f=new Set;function h(t){u(i("function",t)||i("undefined",t),"cannot spy on a non-function value");let e=(...n)=>{if(e.called=!0,e.callCount+=1,e.calls.push(n),e.next){let[p,c]=e.next;if(e.results.push(e.next),e.next=null,p==="ok")return c;throw c}let r,o="ok";if(e.impl)try{r=e.impl(...n),o="ok"}catch(p){r=p,o="error"}let a=[o,r];return r&&i("object",r)&&i("function",r.then)&&r.then(p=>a[1]=p),e.results.push(a),r};Object.defineProperty(e,"length",{value:t?t.length:0}),Object.defineProperty(e,"__isSpy",{value:!0}),Object.defineProperty(e,"returns",{get(){return this.results.map(([,n])=>n)}});let s=()=>{e.called=!1,e.callCount=0,e.results=[],e.calls=[]};return s(),e.impl=t,e.reset=s,e.nextError=n=>(e.next=["error",n],e),e.nextResult=n=>(e.next=["ok",n],e),e}var k=(t,e)=>Object.getOwnPropertyDescriptor(t,e);function E(t,e,s){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 n=()=>typeof e=="string"?[e,"value"]:"getter"in e?[e.getter,"get"]:[e.setter,"set"],[r,o]=n(),a=k(t,r),p=Object.getPrototypeOf(t),c=k(p,r),y=a||c;u(y,`${r} does not exist`),u(y.configurable,`${r} is not declared configurable`);let m=!1;o==="value"&&!y.value&&y.get&&(o="get",m=!0,s=y.get());let g=y[o];s||(s=g);let l=h(s.bind(t)),A=R=>{let S=y,{value:w}=S,T=v(S,["value"]);o!=="value"&&delete T.writable,T[o]=R,Object.defineProperty(a?t:p,r,T)},F=()=>A(g);return l.restore=F,l.getOriginal=()=>g,l.willCall=R=>(l.impl=R.bind(t),l),A(m?()=>l:l),f.add(l),l}function q(){for(let t of f)t.restore();f.clear()}export{q as restoreAll,f as spies,h as spy,E as spyOn}; |
{ | ||
"name": "tinyspy", | ||
"version": "0.0.15", | ||
"version": "0.1.0", | ||
"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
4574