@starbeam/verify
Advanced tools
Comparing version 0.8.8 to 0.8.9
# @starbeam/verify | ||
## 0.8.9 | ||
### Patch Changes | ||
- e459bf2: Fix CJS builds | ||
- Updated dependencies [e459bf2] | ||
- @starbeam/core-utils@0.8.9 | ||
## 0.8.8 | ||
@@ -4,0 +12,0 @@ |
import { isPresentArray } from '@starbeam/core-utils'; | ||
function _classApplyDescriptorSet(receiver, descriptor, value) { | ||
if (descriptor.set) { | ||
descriptor.set.call(receiver, value); | ||
} else { | ||
if (!descriptor.writable) { | ||
throw new TypeError("attempted to set read only private field"); | ||
} | ||
descriptor.value = value; | ||
} | ||
} | ||
function _classExtractFieldDescriptor(receiver, privateMap, action) { | ||
if (!privateMap.has(receiver)) { | ||
throw new TypeError("attempted to " + action + " private field on non-instance"); | ||
} | ||
return privateMap.get(receiver); | ||
} | ||
function _classPrivateFieldSet(receiver, privateMap, value) { | ||
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); | ||
_classApplyDescriptorSet(receiver, descriptor, value); | ||
return value; | ||
} | ||
function _classApplyDescriptorGet(receiver, descriptor) { | ||
if (descriptor.get) { | ||
return descriptor.get.call(receiver); | ||
} | ||
return descriptor.value; | ||
} | ||
function _classPrivateFieldGet(receiver, privateMap) { | ||
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); | ||
return _classApplyDescriptorGet(receiver, descriptor); | ||
} | ||
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } | ||
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } | ||
class VerificationError extends Error { | ||
@@ -75,6 +37,2 @@ constructor(message, expectation) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
var _description = /*#__PURE__*/new WeakMap(); | ||
var _to = /*#__PURE__*/new WeakMap(); | ||
var _actual = /*#__PURE__*/new WeakMap(); | ||
var _when = /*#__PURE__*/new WeakMap(); | ||
class Expectation { | ||
@@ -94,59 +52,47 @@ static create(description) { | ||
} | ||
return new Expectation(_classPrivateFieldGet(specified, _description), _classPrivateFieldGet(specified, _to) ?? _classPrivateFieldGet(associated, _to), _classPrivateFieldGet(specified, _actual) ?? _classPrivateFieldGet(associated, _actual), _classPrivateFieldGet(specified, _when) ?? _classPrivateFieldGet(associated, _when)); | ||
return new Expectation(specified.#description, specified.#to ?? associated.#to, specified.#actual ?? associated.#actual, specified.#when ?? associated.#when); | ||
} | ||
#description; | ||
#to; | ||
#actual; | ||
#when; | ||
constructor(description, to, got, when) { | ||
_classPrivateFieldInitSpec(this, _description, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInitSpec(this, _to, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInitSpec(this, _actual, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldInitSpec(this, _when, { | ||
writable: true, | ||
value: void 0 | ||
}); | ||
_classPrivateFieldSet(this, _description, description); | ||
_classPrivateFieldSet(this, _to, to); | ||
_classPrivateFieldSet(this, _actual, got); | ||
_classPrivateFieldSet(this, _when, when); | ||
this.#description = description; | ||
this.#to = to; | ||
this.#actual = got; | ||
this.#when = when; | ||
} | ||
as(description) { | ||
return new Expectation(description, _classPrivateFieldGet(this, _to), _classPrivateFieldGet(this, _actual), _classPrivateFieldGet(this, _when)); | ||
return new Expectation(description, this.#to, this.#actual, this.#when); | ||
} | ||
update(updater) { | ||
const description = updater.description ? updater.description(_classPrivateFieldGet(this, _description)) : _classPrivateFieldGet(this, _description); | ||
const updatedTo = updater.to ? updater.to(_classPrivateFieldGet(this, _to)) : _classPrivateFieldGet(this, _to); | ||
const to = typeof updatedTo === "string" ? [toRelationship(_classPrivateFieldGet(this, _to)) ?? "to be", updatedTo] : updatedTo; | ||
const actual = updater.actual ? updater.actual(_classPrivateFieldGet(this, _actual)) : _classPrivateFieldGet(this, _actual); | ||
return new Expectation(description, to, actual, updater.when ? updater.when(_classPrivateFieldGet(this, _when)) : _classPrivateFieldGet(this, _when)); | ||
const description = updater.description ? updater.description(this.#description) : this.#description; | ||
const updatedTo = updater.to ? updater.to(this.#to) : this.#to; | ||
const to = typeof updatedTo === "string" ? [toRelationship(this.#to) ?? "to be", updatedTo] : updatedTo; | ||
const actual = updater.actual ? updater.actual(this.#actual) : this.#actual; | ||
return new Expectation(description, to, actual, updater.when ? updater.when(this.#when) : this.#when); | ||
} | ||
toBe(kind) { | ||
return new Expectation(_classPrivateFieldGet(this, _description), ["to be", kind], _classPrivateFieldGet(this, _actual), _classPrivateFieldGet(this, _when)); | ||
return new Expectation(this.#description, ["to be", kind], this.#actual, this.#when); | ||
} | ||
toHave(items) { | ||
return new Expectation(_classPrivateFieldGet(this, _description), ["to have", items], _classPrivateFieldGet(this, _actual), _classPrivateFieldGet(this, _when)); | ||
return new Expectation(this.#description, ["to have", items], this.#actual, this.#when); | ||
} | ||
butGot(kind) { | ||
return new Expectation(_classPrivateFieldGet(this, _description), _classPrivateFieldGet(this, _to), typeof kind === "string" ? () => kind : kind, _classPrivateFieldGet(this, _when)); | ||
return new Expectation(this.#description, this.#to, typeof kind === "string" ? () => kind : kind, this.#when); | ||
} | ||
when(situation) { | ||
return new Expectation(_classPrivateFieldGet(this, _description), _classPrivateFieldGet(this, _to), _classPrivateFieldGet(this, _actual), situation); | ||
return new Expectation(this.#description, this.#to, this.#actual, situation); | ||
} | ||
message(input) { | ||
let message = ``; | ||
if (_classPrivateFieldGet(this, _when)) { | ||
message += `When ${_classPrivateFieldGet(this, _when)}: `; | ||
if (this.#when) { | ||
message += `When ${this.#when}: `; | ||
} | ||
message += `Expected ${_classPrivateFieldGet(this, _description) ?? "value"}`; | ||
if (_classPrivateFieldGet(this, _to)) { | ||
message += ` ${toRelationship(_classPrivateFieldGet(this, _to))} ${toKind(_classPrivateFieldGet(this, _to))}`; | ||
message += `Expected ${this.#description ?? "value"}`; | ||
if (this.#to) { | ||
message += ` ${toRelationship(this.#to)} ${toKind(this.#to)}`; | ||
} | ||
if (_classPrivateFieldGet(this, _actual)) { | ||
message += `, but it was ${String(_classPrivateFieldGet(this, _actual).call(this, input))}`; | ||
if (this.#actual) { | ||
message += `, but it was ${String(this.#actual(input))}`; | ||
} | ||
@@ -153,0 +99,0 @@ return message; |
{ | ||
"name": "@starbeam/verify", | ||
"version": "0.8.8", | ||
"version": "0.8.9", | ||
"type": "module", | ||
@@ -16,3 +16,3 @@ "main": "dist/index.cjs", | ||
"dependencies": { | ||
"@starbeam/core-utils": "^0.8.8" | ||
"@starbeam/core-utils": "^0.8.9" | ||
}, | ||
@@ -19,0 +19,0 @@ "devDependencies": { |
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
134560
1671
Updated@starbeam/core-utils@^0.8.9