jest_expect.js 1.9 KB

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