@plugjs/expect5
Version:
Unit Testing for the PlugJS Build System ========================================
99 lines (97 loc) • 3.88 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// expectation/async.ts
var async_exports = {};
__export(async_exports, {
AsyncExpectations: () => AsyncExpectations
});
module.exports = __toCommonJS(async_exports);
var import_expectations = require("./expectations.cjs");
var import_types = require("./types.cjs");
var AsyncExpectations = class extends import_expectations.Expectations {
/**
* Create an {@link AsyncExpectations} instance associated with the specified
* value and error remarks.
*/
constructor(value, remarks) {
super(value, remarks);
}
toBeRejected(assertionOrMatcher) {
return Promise.resolve().then(() => {
this.toHaveProperty("then", (assert) => assert.toBeA("function"));
return Promise.allSettled([Promise.resolve(this.value)]);
}).then(([settlement]) => {
if (settlement.status === "rejected") {
if ((0, import_types.isMatcher)(assertionOrMatcher)) {
assertionOrMatcher.expect(settlement.reason);
} else if (assertionOrMatcher) {
assertionOrMatcher(new import_expectations.Expectations(settlement.reason, this.remarks));
}
return this;
}
this._fail("to be rejected");
});
}
/* ------------------------------------------------------------------------ */
/**
* Expects the value to be a {@link PromiseLike} _rejected_ with an
* {@link Error} {@link Expectations.toStrictlyEqual _strictly equal_}
* to the one specified.
*
* Negation: {@link Expectations.toBeResolved `toBeResolved(...)`}
*/
toBeRejectedWith(expected) {
return this.toBeRejected((assert) => assert.toStrictlyEqual(expected));
}
toBeRejectedWithError(constructorOrMessage, maybeMessage) {
const [constructor, message] = typeof constructorOrMessage === "function" ? [constructorOrMessage, maybeMessage] : [Error, constructorOrMessage];
return this.toBeRejected((assert) => assert.toBeError(constructor, message));
}
toBeResolved(assertion) {
return Promise.resolve().then(() => {
this.toHaveProperty("then", (assert) => assert.toBeA("function"));
return Promise.allSettled([Promise.resolve(this.value)]);
}).then(([settlement]) => {
if (settlement.status === "fulfilled") {
if ((0, import_types.isMatcher)(assertion)) {
assertion.expect(settlement.value);
} else if (assertion) {
assertion(new import_expectations.Expectations(settlement.value, this.remarks));
}
return this;
}
this._fail("to be resolved");
});
}
/* ------------------------------------------------------------------------ */
/**
* Expects the value to be a {@link PromiseLike} _resolved_ with a value
* {@link Expectations.toEqual _deeply equal_} to the one specified.
*
* Negation: {@link Expectations.toBeRejected `toBeRejected(...)`}
*/
toBeResolvedWith(expected) {
return this.toBeResolved((assert) => assert.toEqual(expected));
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AsyncExpectations
});
//# sourceMappingURL=async.cjs.map