Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tinyspy

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinyspy - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

6

dist/index.d.ts

@@ -28,8 +28,8 @@ declare let spies: Set<SpyImpl<any[], any>>;

declare type AnyFunction = (...args: any[]) => any;
declare type Procedure = (...args: any[]) => any;
declare type Methods<T> = {
[Key in keyof T]-?: T[Key] extends AnyFunction ? Key : never;
[K in keyof T]-?: T[K] extends Procedure ? K : never;
}[keyof T];
declare type Getters<T> = {
[Key in keyof T]-?: T[Key] extends AnyFunction ? never : Key;
[K in keyof T]-?: T[K] extends Procedure ? never : K;
}[keyof T];

@@ -36,0 +36,0 @@ declare function spyOn<T, S extends Getters<T>>(obj: T, methodName: {

@@ -1,1 +0,1 @@

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 p(t,e){return typeof e===t}var f=new Set;function h(t){u(p("function",t)||p("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[l,c]=e.next;if(e.results.push(e.next),e.next=null,l==="ok")return c;throw c}let r,o="ok";if(e.impl)try{r=e.impl(...n),o="ok"}catch(l){r=l,o="error"}let a=[o,r];return r&&p("object",r)&&p("function",r.then)&&r.then(l=>a[1]=l),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(!p("undefined",t),"spyOn could not find an object to spy upon"),u(p("object",t)||p("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),l=Object.getPrototypeOf(t),c=l&&k(l,r),y=a||c;u(y,`${r} does not exist`),u(y.configurable,`${r} is not declared configurable`);let R=!1;o==="value"&&!y.value&&y.get&&(o="get",R=!0,s=y.get());let d=y[o];s||(s=d);let i=h(s.bind(t)),A=T=>{let S=y,{value:w}=S,m=v(S,["value"]);o!=="value"&&delete m.writable,m[o]=T,Object.defineProperty(a?t:l,r,m)},F=()=>A(d);return i.restore=F,i.getOriginal=()=>R?d():d,i.willCall=T=>(i.impl=T.bind(t),i),A(R?()=>i:i),f.add(i),i}function q(){for(let t of f)t.restore();f.clear()}export{q as restoreAll,f as spies,h as spy,E as spyOn};
var h=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&&h)for(var r of h(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=(...r)=>{if(e.called=!0,e.callCount+=1,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(...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)),O=m=>{let A=a,{value:F}=A,T=P(A,["value"]);l!=="value"&&delete T.writable,T[l]=m,Object.defineProperty(y?t:p,s,T)},K=()=>O(d);o.restore=K,o.getOriginal=()=>R?d():d,o.willCall=m=>(o.impl=m.bind(t),o);let S=n.name||"spy",v="bound ";return n.name.startsWith(v)&&(S=n.name.slice(v.length)),Object.defineProperty(o,"name",{value:S}),O(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.0",
"version": "0.2.1",
"type": "module",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc