toBeTruthy.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var toBeTruthy_exports = {};
  20. __export(toBeTruthy_exports, {
  21. toBeTruthy: () => toBeTruthy
  22. });
  23. module.exports = __toCommonJS(toBeTruthy_exports);
  24. var import_util = require("../util");
  25. var import_matcherHint = require("./matcherHint");
  26. async function toBeTruthy(matcherName, receiver, receiverType, expected, arg, query, options = {}) {
  27. (0, import_util.expectTypes)(receiver, [receiverType], matcherName);
  28. const matcherOptions = {
  29. isNot: this.isNot,
  30. promise: this.promise
  31. };
  32. const timeout = options.timeout ?? this.timeout;
  33. const { matches: pass, log, timedOut, received } = await query(!!this.isNot, timeout);
  34. if (pass === !this.isNot) {
  35. return {
  36. name: matcherName,
  37. message: () => "",
  38. pass,
  39. expected
  40. };
  41. }
  42. const notFound = received === import_matcherHint.kNoElementsFoundError ? received : void 0;
  43. let printedReceived;
  44. let printedExpected;
  45. if (pass) {
  46. printedExpected = `Expected: not ${expected}`;
  47. printedReceived = `Received: ${notFound ? import_matcherHint.kNoElementsFoundError : expected}`;
  48. } else {
  49. printedExpected = `Expected: ${expected}`;
  50. printedReceived = `Received: ${notFound ? import_matcherHint.kNoElementsFoundError : received}`;
  51. }
  52. const message = () => {
  53. const header = (0, import_matcherHint.matcherHint)(this, receiver, matcherName, "locator", arg, matcherOptions, timedOut ? timeout : void 0, `${printedExpected}
  54. ${printedReceived}`);
  55. const logText = (0, import_util.callLogText)(log);
  56. return `${header}${logText}`;
  57. };
  58. return {
  59. message,
  60. pass,
  61. actual: received,
  62. name: matcherName,
  63. expected,
  64. log,
  65. timeout: timedOut ? timeout : void 0
  66. };
  67. }
  68. // Annotate the CommonJS export names for ESM import in node:
  69. 0 && (module.exports = {
  70. toBeTruthy
  71. });