How to use the enzyme-adapter-utils.getMaskedContext function in enzyme-adapter-utils

To help you get started, we’ve selected a few enzyme-adapter-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airbnb / enzyme / packages / enzyme-adapter-react-16.2 / src / ReactSixteenTwoAdapter.js View on Github external
render(el, unmaskedContext) {
        cachedNode = el;
        /* eslint consistent-return: 0 */
        if (typeof el.type === 'string') {
          isDOM = true;
        } else {
          isDOM = false;
          const { type: Component } = el;

          const isStateful = Component.prototype && (
            Component.prototype.isReactComponent
            || Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
          );
          const context = getMaskedContext(Component.contextTypes, unmaskedContext);

          if (!isStateful && typeof Component === 'function') {
            const wrappedEl = Object.assign(
              (...args) => Component(...args), // eslint-disable-line new-cap
              Component,
            );
            return withSetStateAllowed(() => renderer.render({ ...el, type: wrappedEl }, context));
          }
          if (isStateful) {
            // fix react bug; see implementation of `getEmptyStateValue`
            const emptyStateValue = getEmptyStateValue();
            if (emptyStateValue) {
              Object.defineProperty(Component.prototype, 'state', {
                configurable: true,
                enumerable: true,
                get() {
github airbnb / enzyme / packages / enzyme-adapter-react-16.1 / src / ReactSixteenOneAdapter.js View on Github external
render(el, unmaskedContext) {
        cachedNode = el;
        /* eslint consistent-return: 0 */
        if (typeof el.type === 'string') {
          isDOM = true;
        } else {
          isDOM = false;
          const { type: Component } = el;

          const isStateful = Component.prototype && (
            Component.prototype.isReactComponent
            || Array.isArray(Component.__reactAutoBindPairs) // fallback for createClass components
          );
          const context = getMaskedContext(Component.contextTypes, unmaskedContext);

          if (!isStateful && typeof Component === 'function') {
            const wrappedEl = Object.assign(
              (...args) => Component(...args), // eslint-disable-line new-cap
              Component,
            );
            return withSetStateAllowed(() => renderer.render({ ...el, type: wrappedEl }, context));
          }
          if (isStateful) {
            // fix react bug; see implementation of `getEmptyStateValue`
            const emptyStateValue = getEmptyStateValue();
            if (emptyStateValue) {
              Object.defineProperty(Component.prototype, 'state', {
                configurable: true,
                enumerable: true,
                get() {
github airbnb / enzyme / packages / enzyme-adapter-react-16 / src / ReactSixteenAdapter.js View on Github external
let renderedEl = el;
          if (isLazy(renderedEl)) {
            throw TypeError('`React.lazy` is not supported by shallow rendering.');
          }
          if (isSuspense(renderedEl)) {
            let { children } = renderedEl.props;
            if (suspenseFallback) {
              const { fallback } = renderedEl.props;
              children = replaceLazyWithFallback(children, fallback);
            }
            const FakeSuspenseWrapper = () => children;
            renderedEl = React.createElement(FakeSuspenseWrapper, null, children);
          }
          const { type: Component } = renderedEl;

          const context = getMaskedContext(Component.contextTypes, unmaskedContext);

          if (isMemo(el.type)) {
            const { type: InnerComp, compare } = el.type;

            return withSetStateAllowed(() => renderer.render(
              { ...el, type: wrapPureComponent(InnerComp, compare) },
              context,
            ));
          }

          if (!isStateful(Component) && typeof Component === 'function') {
            return withSetStateAllowed(() => renderer.render(
              { ...renderedEl, type: wrapFunctionalComponent(Component) },
              context,
            ));
          }