"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createComponentWithContext = createComponentWithContext;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _enzyme = require("enzyme");
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

// since the 'shallow' from 'enzyme' doesn't support context API for React 16 and above (https://github.com/facebook/react/pull/14329)
// we use this workaround where define legacy contextTypes for react class component
function createComponentWithContext(MyComponent, props, mockedContext) {
  MyComponent.contextTypes = {
    services: _propTypes.default.object
  };
  return (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(MyComponent, props), {
    context: {
      services: mockedContext
    }
  });
}