jestExpect.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _expect = _interopRequireDefault(require('expect'));
  7. var _jestSnapshot = require('jest-snapshot');
  8. function _interopRequireDefault(obj) {
  9. return obj && obj.__esModule ? obj : {default: obj};
  10. }
  11. /**
  12. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  13. *
  14. * This source code is licensed under the MIT license found in the
  15. * LICENSE file in the root directory of this source tree.
  16. */
  17. var _default = config => {
  18. global.expect = _expect.default;
  19. _expect.default.setState({
  20. expand: config.expand
  21. });
  22. _expect.default.extend({
  23. toMatchInlineSnapshot: _jestSnapshot.toMatchInlineSnapshot,
  24. toMatchSnapshot: _jestSnapshot.toMatchSnapshot,
  25. toThrowErrorMatchingInlineSnapshot:
  26. _jestSnapshot.toThrowErrorMatchingInlineSnapshot,
  27. toThrowErrorMatchingSnapshot: _jestSnapshot.toThrowErrorMatchingSnapshot
  28. });
  29. _expect.default.addSnapshotSerializer = _jestSnapshot.addSerializer;
  30. const jasmine = global.jasmine;
  31. jasmine.anything = _expect.default.anything;
  32. jasmine.any = _expect.default.any;
  33. jasmine.objectContaining = _expect.default.objectContaining;
  34. jasmine.arrayContaining = _expect.default.arrayContaining;
  35. jasmine.stringMatching = _expect.default.stringMatching;
  36. jasmine.addMatchers = jasmineMatchersObject => {
  37. const jestMatchersObject = Object.create(null);
  38. Object.keys(jasmineMatchersObject).forEach(name => {
  39. jestMatchersObject[name] = function(...args) {
  40. // use "expect.extend" if you need to use equality testers (via this.equal)
  41. const result = jasmineMatchersObject[name](null, null); // if there is no 'negativeCompare', both should be handled by `compare`
  42. const negativeCompare = result.negativeCompare || result.compare;
  43. return this.isNot
  44. ? negativeCompare.apply(
  45. null, // @ts-ignore
  46. args
  47. )
  48. : result.compare.apply(
  49. null, // @ts-ignore
  50. args
  51. );
  52. };
  53. });
  54. const expect = global.expect;
  55. expect.extend(jestMatchersObject);
  56. };
  57. };
  58. exports.default = _default;