toBeTruthy.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.toBeTruthy = toBeTruthy;
  6. var _util = require("../util");
  7. var _matcherHint = require("./matcherHint");
  8. var _globals = require("../common/globals");
  9. /**
  10. * Copyright Microsoft Corporation. All rights reserved.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. async function toBeTruthy(matcherName, receiver, receiverType, expected, unexpected, arg, query, options = {}) {
  25. (0, _util.expectTypes)(receiver, [receiverType], matcherName);
  26. const matcherOptions = {
  27. isNot: this.isNot,
  28. promise: this.promise
  29. };
  30. const timeout = (0, _globals.currentExpectTimeout)(options);
  31. const {
  32. matches,
  33. log,
  34. timedOut
  35. } = await query(!!this.isNot, timeout);
  36. const actual = matches ? expected : unexpected;
  37. const message = () => {
  38. const header = (0, _matcherHint.matcherHint)(this, receiver, matcherName, 'locator', arg, matcherOptions, timedOut ? timeout : undefined);
  39. const logText = (0, _util.callLogText)(log);
  40. return matches ? `${header}Expected: not ${expected}\nReceived: ${expected}${logText}` : `${header}Expected: ${expected}\nReceived: ${unexpected}${logText}`;
  41. };
  42. return {
  43. message,
  44. pass: matches,
  45. actual,
  46. name: matcherName,
  47. expected,
  48. log,
  49. timeout: timedOut ? timeout : undefined
  50. };
  51. }