Comparing version 0.2.3 to 0.2.4
@@ -1,1 +0,1 @@ | ||
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}; | ||
var A=Object.getOwnPropertySymbols;var w=Object.prototype.hasOwnProperty,K=Object.prototype.propertyIsEnumerable;var O=(t,e)=>{var s={};for(var r in t)w.call(t,r)&&e.indexOf(r)<0&&(s[r]=t[r]);if(t!=null&&A)for(var r of A(t))e.indexOf(r)<0&&K.call(t,r)&&(s[r]=t[r]);return s};function y(t,e){if(!t)throw new Error(e)}function a(t,e){return typeof e===t}var c=new Set;function h(t){y(a("function",t)||a("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[l,d]=e.next;if(e.results.push(e.next),e.next=null,l==="ok")return d;throw d}let n,o="ok";if(e.impl)try{n=e.impl.apply(this,r),o="ok"}catch(l){n=l,o="error"}let f=[o,n];return n&&a("object",n)&&a("function",n.then)&&n.then(l=>f[1]=l),e.results.push(f),n};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 s=()=>{e.called=!1,e.callCount=0,e.results=[],e.calls=[]};return s(),e.impl=t,e.reset=s,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 E(t,e,s){y(!a("undefined",t),"spyOn could not find an object to spy upon"),y(a("object",t)||a("function",t),"cannot spyOn on a primitive value");let r=()=>typeof e=="string"?[e,"value"]:"getter"in e?[e.getter,"get"]:[e.setter,"set"],[n,o]=r(),f=k(t,n),l=Object.getPrototypeOf(t),d=l&&k(l,n),p=f||d;y(p||n in t,`${n} does not exist`);let R=!1;o==="value"&&p&&!p.value&&p.get&&(o="get",R=!0,s=p.get());let u;p?u=p[o]:o!=="value"?u=()=>t[n]:u=t[n],s||(s=u);let i=h(s),S=T=>{let v=p||{configurable:!0,writable:!0},{value:F}=v,m=O(v,["value"]);o!=="value"&&delete m.writable,m[o]=T,Object.defineProperty(f||!p?t:l,n,m)},P=()=>S(u);return i.restore=P,i.getOriginal=()=>R?u():u,i.willCall=T=>(i.impl=T,i),S(R?()=>i:i),c.add(i),i}function q(){for(let t of c)t.restore();c.clear()}export{q as restoreAll,c as spies,h as spy,E as spyOn}; |
{ | ||
"name": "tinyspy", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"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
4645
50