jest_expect.js 2.0 KB

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