toBeTruthy.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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, locator, receiverType, expected, arg, query, options = {}) {
  27. (0, import_util.expectTypes)(locator, [receiverType], matcherName);
  28. const timeout = options.timeout ?? this.timeout;
  29. const { matches: pass, log, timedOut, received, errorMessage } = await query(!!this.isNot, timeout);
  30. if (pass === !this.isNot) {
  31. return {
  32. name: matcherName,
  33. message: () => "",
  34. pass,
  35. expected
  36. };
  37. }
  38. let printedReceived;
  39. let printedExpected;
  40. if (pass) {
  41. printedExpected = `Expected: not ${expected}`;
  42. printedReceived = errorMessage ? "" : `Received: ${expected}`;
  43. } else {
  44. printedExpected = `Expected: ${expected}`;
  45. printedReceived = errorMessage ? "" : `Received: ${received}`;
  46. }
  47. const message = () => {
  48. return (0, import_matcherHint.formatMatcherMessage)(this, {
  49. matcherName,
  50. expectation: arg,
  51. locator,
  52. timeout,
  53. timedOut,
  54. printedExpected,
  55. printedReceived,
  56. errorMessage,
  57. log
  58. });
  59. };
  60. return {
  61. message,
  62. pass,
  63. actual: received,
  64. name: matcherName,
  65. expected,
  66. log,
  67. timeout: timedOut ? timeout : void 0
  68. };
  69. }
  70. // Annotate the CommonJS export names for ESM import in node:
  71. 0 && (module.exports = {
  72. toBeTruthy
  73. });