tinyspy
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -9,3 +9,3 @@ // src/utils.ts | ||
} | ||
function A(t) { | ||
function w(t) { | ||
return t instanceof Promise; | ||
@@ -21,22 +21,22 @@ } | ||
d(y("function", t) || y("undefined", t), "cannot spy on a non-function value"); | ||
let e = function(...n) { | ||
if (e.called = !0, e.callCount++, e.calls.push(n), e.next) { | ||
let [o, l] = e.next; | ||
if (e.results.push(e.next), e.next = null, o === "ok") | ||
let e = function(...o) { | ||
if (e.called = !0, e.callCount++, e.calls.push(o), e.next) { | ||
let [s, l] = e.next; | ||
if (e.results.push(e.next), e.next = null, s === "ok") | ||
return l; | ||
throw l; | ||
} | ||
let r, s = "ok"; | ||
let r, n = "ok"; | ||
if (e.impl) | ||
try { | ||
r = new.target ? new e.impl(...n) : e.impl.apply(this, n), s = "ok"; | ||
} catch (o) { | ||
throw r = o, s = "error", e.results.push([s, o]), o; | ||
r = e.impl.apply(this, o), n = "ok"; | ||
} catch (s) { | ||
throw r = s, n = "error", e.results.push([n, s]), s; | ||
} | ||
let c = [s, r]; | ||
if (A(r)) { | ||
let o = r.then((l) => c[1] = l).catch((l) => { | ||
let c = [n, r]; | ||
if (w(r)) { | ||
let s = r.then((l) => c[1] = l).catch((l) => { | ||
throw c[0] = "error", c[1] = l, l; | ||
}); | ||
Object.assign(o, r), r = o; | ||
Object.assign(s, r), r = s; | ||
} | ||
@@ -47,3 +47,3 @@ return e.results.push(c), r; | ||
get() { | ||
return this.results.map(([, n]) => n); | ||
return this.results.map(([, o]) => o); | ||
} | ||
@@ -54,3 +54,3 @@ }), f(e, "name", { value: t && t.name || "spy" }); | ||
}; | ||
return i(), e.impl = t, e.reset = i, e.nextError = (n) => (e.next = ["error", n], e), e.nextResult = (n) => (e.next = ["ok", n], e), e; | ||
return i(), e.impl = t, e.reset = i, e.nextError = (o) => (e.next = ["error", o], e), e.nextResult = (o) => (e.next = ["ok", o], e), e; | ||
} | ||
@@ -62,3 +62,3 @@ | ||
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 n = () => { | ||
let o = () => { | ||
if (typeof e != "object") | ||
@@ -73,16 +73,16 @@ return [e, "value"]; | ||
throw new Error("specify getter or setter to spy on"); | ||
}, [r, s] = n(), c = v(t, r), o = Object.getPrototypeOf(t), l = o && v(o, r), a = c || l; | ||
}, [r, n] = o(), c = v(t, r), s = Object.getPrototypeOf(t), l = s && v(s, r), a = c || l; | ||
d(a || r in t, `${String(r)} does not exist`); | ||
let T = !1; | ||
s === "value" && a && !a.value && a.get && (s = "get", T = !0, i = a.get()); | ||
n === "value" && a && !a.value && a.get && (n = "get", T = !0, i = a.get()); | ||
let u; | ||
a ? u = a[s] : s !== "value" ? u = () => t[r] : u = t[r], i || (i = u); | ||
let p = S(i), h = (m) => { | ||
let { value: O, ...w } = a || { | ||
a ? u = a[n] : n !== "value" ? u = () => t[r] : u = t[r], i || (i = u); | ||
let p = S(i), A = (m) => { | ||
let { value: O, ...h } = a || { | ||
configurable: !0, | ||
writable: !0 | ||
}; | ||
s !== "value" && delete w.writable, w[s] = m, f(t, r, w); | ||
}, k = () => h(u); | ||
return p.restore = k, p.getOriginal = () => T ? u() : u, p.willCall = (m) => (p.impl = m, p), h(T ? () => p : p), g.add(p), p; | ||
n !== "value" && delete h.writable, h[n] = m, f(t, r, h); | ||
}, k = () => A(u); | ||
return p.restore = k, p.getOriginal = () => T ? u() : u, p.willCall = (m) => (p.impl = m, p), A(T ? () => p : p), g.add(p), p; | ||
} | ||
@@ -89,0 +89,0 @@ |
{ | ||
"name": "tinyspy", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
Sorry, the diff of this file is not supported yet
10771