jestExpect.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = jestExpect;
  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. /* eslint-disable local/prefer-spread-eventually */
  18. function jestExpect(config) {
  19. global.expect = _expect.default;
  20. _expect.default.setState({
  21. expand: config.expand
  22. });
  23. _expect.default.extend({
  24. toMatchInlineSnapshot: _jestSnapshot.toMatchInlineSnapshot,
  25. toMatchSnapshot: _jestSnapshot.toMatchSnapshot,
  26. toThrowErrorMatchingInlineSnapshot:
  27. _jestSnapshot.toThrowErrorMatchingInlineSnapshot,
  28. toThrowErrorMatchingSnapshot: _jestSnapshot.toThrowErrorMatchingSnapshot
  29. });
  30. _expect.default.addSnapshotSerializer = _jestSnapshot.addSerializer;
  31. const jasmine = global.jasmine;
  32. jasmine.anything = _expect.default.anything;
  33. jasmine.any = _expect.default.any;
  34. jasmine.objectContaining = _expect.default.objectContaining;
  35. jasmine.arrayContaining = _expect.default.arrayContaining;
  36. jasmine.stringMatching = _expect.default.stringMatching;
  37. jasmine.addMatchers = jasmineMatchersObject => {
  38. const jestMatchersObject = Object.create(null);
  39. Object.keys(jasmineMatchersObject).forEach(name => {
  40. jestMatchersObject[name] = function (...args) {
  41. // use "expect.extend" if you need to use equality testers (via this.equal)
  42. const result = jasmineMatchersObject[name](null, null); // if there is no 'negativeCompare', both should be handled by `compare`
  43. const negativeCompare = result.negativeCompare || result.compare;
  44. return this.isNot
  45. ? negativeCompare.apply(
  46. null, // @ts-expect-error
  47. args
  48. )
  49. : result.compare.apply(
  50. null, // @ts-expect-error
  51. args
  52. );
  53. };
  54. });
  55. _expect.default.extend(jestMatchersObject);
  56. };
  57. }