expectation_result_factory.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = expectationResultFactory;
  6. /**
  7. * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  8. *
  9. * This source code is licensed under the MIT license found in the
  10. * LICENSE file in the root directory of this source tree.
  11. *
  12. *
  13. */
  14. function messageFormatter(_ref) {
  15. let error = _ref.error,
  16. message = _ref.message,
  17. passed = _ref.passed;
  18. if (passed) {
  19. return 'Passed.';
  20. }
  21. if (message) {
  22. return message;
  23. }
  24. if (!error) {
  25. return '';
  26. }
  27. return error.message && error.name ? `${error.name}: ${error.message}` : `${error.toString()} thrown`;
  28. }
  29. function stackFormatter(options, errorMessage) {
  30. if (options.passed) {
  31. return '';
  32. }
  33. var _ref2 = options.error || new Error(errorMessage);
  34. const stack = _ref2.stack;
  35. return stack;
  36. }
  37. function expectationResultFactory(options) {
  38. const message = messageFormatter(options);
  39. const stack = stackFormatter(options, message);
  40. if (options.passed) {
  41. return {
  42. error: options.error,
  43. matcherName: options.matcherName,
  44. message,
  45. passed: options.passed,
  46. stack
  47. };
  48. }
  49. return {
  50. actual: options.actual,
  51. error: options.error,
  52. expected: options.expected,
  53. matcherName: options.matcherName,
  54. message,
  55. passed: options.passed,
  56. stack
  57. };
  58. }