Comparing version 0.0.14 to 0.0.15
@@ -1,2 +0,2 @@ | ||
declare let spies: Set<SpyFn<any[], any>>; | ||
declare let spies: Set<SpyImpl<any[], any>>; | ||
declare type ReturnError = ['error', any]; | ||
@@ -14,7 +14,11 @@ declare type ReturnOk<R> = ['ok', R]; | ||
nextResult(result: R): this; | ||
willCall(cb: (...args: A) => R): this; | ||
restore(): void; | ||
reset(): void; | ||
impl: ((...args: A) => R) | undefined; | ||
next: ResultFn<R> | null; | ||
} | ||
interface SpyImpl<A extends any[] = any[], R = any> extends Spy<A, R> { | ||
getOriginal: () => (...args: A) => R; | ||
willCall(cb: (...args: A) => R): this; | ||
restore(): void; | ||
} | ||
interface SpyFn<A extends any[] = any[], R = any> extends Spy<A, R> { | ||
@@ -34,10 +38,10 @@ (...args: A): R; | ||
setter: S; | ||
}, mock?: (arg: T[S]) => void): Spy<[T[S]], void>; | ||
}, mock?: (arg: T[S]) => void): SpyImpl<[T[S]], void>; | ||
declare function spyOn<T, G extends Getters<T>>(obj: T, methodName: { | ||
getter: G; | ||
}, mock?: () => T[G]): Spy<[], T[G]>; | ||
declare function spyOn<T, M extends Methods<T>>(obj: T, methodName: M, mock?: T[M]): T[M] extends (...args: infer A) => infer R ? Spy<A, R> : never; | ||
}, mock?: () => T[G]): SpyImpl<[], T[G]>; | ||
declare function spyOn<T, M extends Methods<T>>(obj: T, methodName: M, mock?: T[M]): T[M] extends (...args: infer A) => infer R ? SpyImpl<A, R> : never; | ||
declare function restoreAll(): void; | ||
export { Spy, SpyFn, restoreAll, spies, spy, spyOn }; | ||
export { Spy, SpyFn, SpyImpl, restoreAll, spies, spy, spyOn }; |
@@ -1,1 +0,1 @@ | ||
var S=Object.getOwnPropertySymbols;var K=Object.prototype.hasOwnProperty,w=Object.prototype.propertyIsEnumerable;var O=(t,r)=>{var e={};for(var s in t)K.call(t,s)&&r.indexOf(s)<0&&(e[s]=t[s]);if(t!=null&&S)for(var s of S(t))r.indexOf(s)<0&&w.call(t,s)&&(e[s]=t[s]);return e};function i(t,r){if(!t)throw new Error(r)}function y(t,r){return typeof r===t}var f=new Set;function h(t){i(y("function",t)||y("undefined",t),"cannot spy on a non-function value");let r=t,e=(...n)=>{if(e.called=!0,e.callCount+=1,e.calls.push(n),e.next){let[u,c]=e.next;if(e.results.push(e.next),e.next=null,u==="ok")return c;throw c}let o,p="ok";if(t)try{o=t(...n),p="ok"}catch(u){o=u,p="error"}return e.results.push([p,o]),o};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.reset=s,e.nextError=n=>(e.next=["error",n],e),e.nextResult=n=>(e.next=["ok",n],e),e.willCall=n=>(t=n,e),e.restore=()=>t=r,e}var m=(t,r)=>Object.getOwnPropertyDescriptor(t,r);function _(t,r,e){i(!y("undefined",t),"spyOn could not find an object to spy upon"),i(y("object",t)||y("function",t),"cannot spyOn on a primitive value");let s=()=>typeof r=="string"?[r,"value"]:"getter"in r?[r.getter,"get"]:[r.setter,"set"],[n,o]=s(),p=m(t,n),u=Object.getPrototypeOf(t),c=m(u,n),l=p||c;i(l,`${n} does not exist`),i(l.configurable,`${n} is not declared configurable`);let R=!1;o==="value"&&!l.value&&l.get&&(o="get",R=!0,e=l.get());let T=l[o];e||(e=T);let a=h(e.bind(t)),A=F=>{let v=l,{value:G}=v,g=O(v,["value"]);o!=="value"&&delete g.writable,g[o]=F,Object.defineProperty(p?t:u,n,g)},k=()=>A(T);return a.restore=k,A(R?()=>a:a),f.add(a),a}function z(){for(let t of f)t.restore();f.clear()}export{z as restoreAll,f as spies,h as spy,_ as spyOn}; | ||
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}; |
{ | ||
"name": "tinyspy", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -8,5 +8,3 @@ # tinyspy | ||
--- | ||
## Docs | ||
Read **[full docs](https://github.com/aslemammad/tinyspy#readme)** on GitHub. |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
4513
50
0
10