Comparing version 2.1.0 to 2.1.1
// src/utils.ts | ||
function R(e, t) { | ||
function g(e, t) { | ||
if (!e) | ||
@@ -12,7 +12,7 @@ throw new Error(t); | ||
} | ||
function g(e, t, n) { | ||
Object.defineProperty(e, t, n); | ||
function f(e, t, r) { | ||
Object.defineProperty(e, t, r); | ||
} | ||
function l(e, t, n) { | ||
Object.defineProperty(e, t, { value: n }); | ||
function l(e, t, r) { | ||
Object.defineProperty(e, t, { value: r }); | ||
} | ||
@@ -26,21 +26,21 @@ | ||
e.called = !1, e.callCount = 0, e.calls = [], e.results = []; | ||
}, C = (e) => (g(e, y, { value: { reset: () => M(e[y]) } }), e[y]), A = (e) => e[y] || C(e); | ||
}, C = (e) => (f(e, y, { value: { reset: () => M(e[y]) } }), e[y]), A = (e) => e[y] || C(e); | ||
function I(e) { | ||
R(i("function", e) || i("undefined", e), "cannot spy on a non-function value"); | ||
g(i("function", e) || i("undefined", e), "cannot spy on a non-function value"); | ||
let t = function(...o) { | ||
let r = A(t); | ||
if (r.called = !0, r.callCount++, r.calls.push(o), r.next) { | ||
let [p, s] = r.next; | ||
if (r.results.push(r.next), r.next = null, p === "ok") | ||
let n = A(t); | ||
if (n.called = !0, n.callCount++, n.calls.push(o), n.next) { | ||
let [p, s] = n.next; | ||
if (n.results.push(n.next), n.next = null, p === "ok") | ||
return s; | ||
throw s; | ||
} | ||
let a, f = "ok"; | ||
if (r.impl) | ||
let a, d = "ok"; | ||
if (n.impl) | ||
try { | ||
a = r.impl.apply(this, o), f = "ok"; | ||
a = n.impl.apply(this, o), d = "ok"; | ||
} catch (p) { | ||
throw a = p, f = "error", r.results.push([f, p]), p; | ||
throw a = p, d = "error", n.results.push([d, p]), p; | ||
} | ||
let u = [f, a]; | ||
let u = [d, a]; | ||
if (b(a)) { | ||
@@ -52,13 +52,13 @@ let p = a.then((s) => u[1] = s).catch((s) => { | ||
} | ||
return r.results.push(u), a; | ||
return n.results.push(u), a; | ||
}; | ||
l(t, "_isMockFunction", !0), l(t, "length", e ? e.length : 0), l(t, "name", e && e.name || "spy"); | ||
let n = A(t); | ||
return n.reset(), n.impl = e, t; | ||
let r = A(t); | ||
return r.reset(), r.impl = e, t; | ||
} | ||
function v(e) { | ||
let t = A(e); | ||
g(e, "returns", { | ||
get: () => t.results.map(([, n]) => n) | ||
}), ["called", "callCount", "results", "calls", "reset", "impl"].forEach((n) => g(e, n, { get: () => t[n], set: (o) => t[n] = o })), l(e, "nextError", (n) => (t.next = ["error", n], t)), l(e, "nextResult", (n) => (t.next = ["ok", n], t)); | ||
f(e, "returns", { | ||
get: () => t.results.map(([, r]) => r) | ||
}), ["called", "callCount", "results", "calls", "reset", "impl"].forEach((r) => f(e, r, { get: () => t[r], set: (o) => t[r] = o })), l(e, "nextError", (r) => (t.next = ["error", r], t)), l(e, "nextResult", (r) => (t.next = ["ok", r], t)); | ||
} | ||
@@ -74,4 +74,4 @@ | ||
var P = (e, t) => Object.getOwnPropertyDescriptor(e, t); | ||
function E(e, t, n) { | ||
R(!i("undefined", e), "spyOn could not find an object to spy upon"), R(i("object", e) || i("function", e), "cannot spyOn on a primitive value"); | ||
function E(e, t, r) { | ||
g(!i("undefined", e), "spyOn could not find an object to spy upon"), g(i("object", e) || i("function", e), "cannot spyOn on a primitive value"); | ||
let o = () => { | ||
@@ -87,9 +87,9 @@ if (!i("object", t)) | ||
throw new Error("specify getter or setter to spy on"); | ||
}, [r, a] = o(), f = P(e, r), u = Object.getPrototypeOf(e), p = u && P(u, r), s = f || p; | ||
R(s || r in e, `${String(r)} does not exist`); | ||
}, [n, a] = o(), d = P(e, n), u = Object.getPrototypeOf(e), p = u && P(u, n), s = d || p; | ||
g(s || n in e, `${String(n)} does not exist`); | ||
let w = !1; | ||
a === "value" && s && !s.value && s.get && (a = "get", w = !0, n = s.get()); | ||
a === "value" && s && !s.value && s.get && (a = "get", w = !0, r = s.get()); | ||
let c; | ||
s ? c = s[a] : a !== "value" ? c = () => e[r] : c = e[r], n || (n = c); | ||
let d = I(n), O = (h) => { | ||
s ? c = s[a] : a !== "value" ? c = () => e[n] : c = e[n], r || (r = c); | ||
let x = I(r), O = (h) => { | ||
let { value: G, ...k } = s || { | ||
@@ -99,10 +99,10 @@ configurable: !0, | ||
}; | ||
a !== "value" && delete k.writable, k[a] = h, g(e, r, k); | ||
}, K = () => O(c), T = d[y]; | ||
return l(T, "restore", K), l(T, "getOriginal", () => w ? c() : c), l(T, "willCall", (h) => (T.impl = h, d)), O(w ? () => d : d), m.add(d), d; | ||
a !== "value" && delete k.writable, k[a] = h, f(e, n, k); | ||
}, K = () => s ? f(e, n, s) : O(c), T = x[y]; | ||
return l(T, "restore", K), l(T, "getOriginal", () => w ? c() : c), l(T, "willCall", (h) => (T.impl = h, x)), O(w ? () => x : x), m.add(x), x; | ||
} | ||
function W(e, t, n) { | ||
let o = E(e, t, n); | ||
return v(o), ["restore", "getOriginal", "willCall"].forEach((r) => { | ||
l(o, r, o[y][r]); | ||
function W(e, t, r) { | ||
let o = E(e, t, r); | ||
return v(o), ["restore", "getOriginal", "willCall"].forEach((n) => { | ||
l(o, n, o[y][n]); | ||
}), o; | ||
@@ -109,0 +109,0 @@ } |
{ | ||
"name": "tinyspy", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
Sorry, the diff of this file is not supported yet
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
13361