"use strict";

var _react = _interopRequireDefault(require("react"));

var _enzyme = _interopRequireWildcard(require("enzyme"));

var _ = require("../");

var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

_enzyme.default.configure({
  adapter: new _enzymeAdapterReact.default()
});

var suppressError = function suppressError() {
  // eslint-disable-next-line no-console
  console.error = function () {};
};

describe('ErrorBoundary', function () {
  it('should render an error message', function () {
    suppressError();

    var BadComponent = function BadComponent() {
      return _react.default.createElement("div", null, undefined.map);
    };

    var ErrorBoundedComponent = (0, _.withErrorBoundary)(BadComponent);
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(ErrorBoundedComponent, null));
    expect(wrapper.text()).toEqual('Something went wrong.');
  });
  it('should render the component if there is no exception', function () {
    var GoodComponent = function GoodComponent() {
      return _react.default.createElement("div", null, "Good");
    };

    var ErrorBoundedComponent = (0, _.withErrorBoundary)(GoodComponent);
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(ErrorBoundedComponent, null));
    expect(wrapper.text()).toEqual('Good');
  });
});