Socket
Socket
Sign inDemoInstall

tinyspy

Package Overview
Dependencies
52
Maintainers
3
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

47

dist/index.js

@@ -6,5 +6,8 @@ // src/utils.ts

}
function u(t, e) {
function y(t, e) {
return typeof e === t;
}
function v(t) {
return t instanceof Promise;
}
function f(t, e, i) {

@@ -15,5 +18,5 @@ Object.defineProperty(t, e, i);

// src/spy.ts
var g = /* @__PURE__ */ new Set();
function S(t) {
d(u("function", t) || u("undefined", t), "cannot spy on a non-function value");
var x = /* @__PURE__ */ new Set();
function A(t) {
d(y("function", t) || y("undefined", t), "cannot spy on a non-function value");
let e = function(...o) {

@@ -34,3 +37,3 @@ if (e.called = !0, e.callCount++, e.calls.push(o), e.next) {

let c = [n, r];
if (r && u("object", r) && u("function", r.then)) {
if (v(r)) {
let s = r.then((l) => c[1] = l).catch((l) => {

@@ -55,5 +58,5 @@ throw c[0] = "error", c[1] = l, l;

// src/spyOn.ts
var v = (t, e) => Object.getOwnPropertyDescriptor(t, e);
function I(t, e, i) {
d(!u("undefined", t), "spyOn could not find an object to spy upon"), d(u("object", t) || u("function", t), "cannot spyOn on a primitive value");
var k = (t, e) => Object.getOwnPropertyDescriptor(t, e);
function C(t, e, i) {
d(!y("undefined", t), "spyOn could not find an object to spy upon"), d(y("object", t) || y("function", t), "cannot spyOn on a primitive value");
let o = () => {

@@ -69,10 +72,10 @@ if (typeof e != "object")

throw new Error("specify getter or setter to spy on");
}, [r, n] = o(), c = v(t, r), s = Object.getPrototypeOf(t), l = s && v(s, r), a = c || l;
}, [r, n] = o(), c = k(t, r), s = Object.getPrototypeOf(t), l = s && k(s, r), a = c || l;
d(a || r in t, `${String(r)} does not exist`);
let T = !1;
n === "value" && a && !a.value && a.get && (n = "get", T = !0, i = a.get());
let y;
a ? y = a[n] : n !== "value" ? y = () => t[r] : y = t[r], i || (i = y);
let p = S(i), A = (m) => {
let { value: w, ...h } = a || {
let u;
a ? u = a[n] : n !== "value" ? u = () => t[r] : u = t[r], i || (i = u);
let p = A(i), S = (m) => {
let { value: O, ...h } = a || {
configurable: !0,

@@ -82,17 +85,17 @@ writable: !0

n !== "value" && delete h.writable, h[n] = m, f(t, r, h);
}, k = () => A(y);
return p.restore = k, p.getOriginal = () => T ? y() : y, p.willCall = (m) => (p.impl = m, p), A(T ? () => p : p), g.add(p), p;
}, w = () => S(u);
return p.restore = w, p.getOriginal = () => T ? u() : u, p.willCall = (m) => (p.impl = m, p), S(T ? () => p : p), x.add(p), p;
}
// src/restoreAll.ts
function G() {
for (let t of g)
function q() {
for (let t of x)
t.restore();
g.clear();
x.clear();
}
export {
G as restoreAll,
g as spies,
S as spy,
I as spyOn
q as restoreAll,
x as spies,
A as spy,
C as spyOn
};
{
"name": "tinyspy",
"version": "1.0.0",
"version": "1.0.1",
"type": "module",

@@ -35,2 +35,5 @@ "main": "./dist/index.cjs",

},
"dependencies": {
"changelogithub": "^0.6.5"
},
"scripts": {

@@ -37,0 +40,0 @@ "publish": "npm run build && clean-publish"

@@ -5,6 +5,8 @@ # tinyspy

A `8KB` package for minimal and easy testing with no dependencies.
A `9KB` package for minimal and easy testing with no dependencies.
This package was created for having a tiny spy library to use in `vitest`, but it can also be used in `jest` and other test environments.
_In case you need more tiny libraries like tinypool or tinyspy, please consider submitting an [RFC](https://github.com/tinylibs/rfcs)_
## Docs
Read **[full docs](https://github.com/tinylibs/tinyspy#readme)** on GitHub.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc