How to use enzyme-adapter-react-helper - 7 common examples

To help you get started, we’ve selected a few enzyme-adapter-react-helper 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-15.4 / src / ReactFifteenFourAdapter.js View on Github external
invokeSetStateCallback(instance, callback) {
    // React in >= 15.4, and < 16 pass undefined to a setState callback
    const invoke = ifReact(
      '^15.4',
      () => { callback.call(instance, undefined); },
      () => { super.invokeSetStateCallback(instance, callback); },
    );
    invoke();
  }
github airbnb / enzyme / packages / enzyme-adapter-react-15.4 / src / ReactFifteenFourAdapter.js View on Github external
invokeSetStateCallback(instance, callback) {
    // React in >= 15.4, and < 16 pass undefined to a setState callback
    const invoke = ifReact(
      '^15.4',
      () => { callback.call(instance, undefined); },
      () => { super.invokeSetStateCallback(instance, callback); },
    );
    invoke();
  }
}
github airbnb / prop-types / test / ref.jsx View on Github external
const itIfReact = (version, ...args) => ifReact(version, () => it(...args), () => it.skip(...args));
github airbnb / prop-types / test / helpers / getComponentName.js View on Github external
const itIfReact = (version, ...args) => ifReact(version, () => it(...args), () => it.skip(...args));
github tajo / react-portal / __tests__ / PortalWithState.js View on Github external
ReactDOM.unmountComponentAtNode(document.getElementById('root'));
  document.body.innerHTML = '';
});

ifReact('>= 16', test, test.skip)('should not mount portal by default', () => {
  ReactDOM.render(
    <PortalWithState>{({ portal }) => portal('Foo')}</PortalWithState>,
    document.getElementById('root')
  );
  expect(document.body.firstChild.outerHTML).toBe('<div id="root"></div>');
  expect(document.body.lastChild.outerHTML).toBe(
    document.body.lastChild.outerHTML
  );
});

ifReact('< 16', test, test.skip)('should not mount portal by default', () => {
  ReactDOM.render(
    <PortalWithState>{({ portal }) => portal('Foo')}</PortalWithState>,
    document.getElementById('root')
  );
  expect(document.body.firstChild.outerHTML).toBe(
    '<div id="root"><!-- react-empty: 1 --></div>'
  );
  expect(document.body.lastChild.outerHTML).toBe(
    document.body.lastChild.outerHTML
  );
});

ifReact('>= 16', test, test.skip)(
  'should mount portal by default with defaultOpen',
  () => {
    ReactDOM.render(
github tajo / react-portal / __tests__ / PortalWithState.js View on Github external
import React from 'react';
import ReactDOM from 'react-dom';
import ifReact from 'enzyme-adapter-react-helper/build/ifReact';
import PortalWithState from '../src/PortalWithState';

beforeEach(() => {
  document.body.innerHTML = '<div id="root"></div>';
});

afterEach(() => {
  ReactDOM.unmountComponentAtNode(document.getElementById('root'));
  document.body.innerHTML = '';
});

ifReact('>= 16', test, test.skip)('should not mount portal by default', () => {
  ReactDOM.render(
    <PortalWithState>{({ portal }) => portal('Foo')}</PortalWithState>,
    document.getElementById('root')
  );
  expect(document.body.firstChild.outerHTML).toBe('<div id="root"></div>');
  expect(document.body.lastChild.outerHTML).toBe(
    document.body.lastChild.outerHTML
  );
});

ifReact('< 16', test, test.skip)('should not mount portal by default', () => {
  ReactDOM.render(
    <PortalWithState>{({ portal }) => portal('Foo')}</PortalWithState>,
    document.getElementById('root')
  );
  expect(document.body.firstChild.outerHTML).toBe(
github tajo / react-portal / examples / index.js View on Github external
this.setState(prevState => ({
              isPortalTwoActive: !prevState.isPortalTwoActive
            }))
          }
        >
          Toggle
        </button>
        {this.state.isPortalTwoActive && (
          <Portal node={document && document.getElementById('user-node')}>
            <p>This thing was portaled with custom node!</p>
          </Portal>
        )}

        <h2>PortalWithState</h2>
        <PortalWithState closeOnOutsideClick closeOnEsc>
          {ifReact(
            '< 16.2',
            ({ openPortal, closePortal, isOpen, portal }) => (
              <div>
                <button key="foo" onClick={openPortal}>
                  Open Portal {isOpen && '(this counts as an outside click)'}
                </button>
                {portal(
                  <p>
                    This is more advanced Portal. It handles its own state.{' '}
                    <button onClick={closePortal}>Close me!</button>, hit ESC or
                    click outside of me.
                  </p>
                )}
              </div>
            ),
            ({ openPortal, closePortal, isOpen, portal }) => (

enzyme-adapter-react-helper

JavaScript Testing utilities for React

MIT
Latest version published 5 months ago

Package Health Score

80 / 100
Full package analysis

Popular enzyme-adapter-react-helper functions

Popular JavaScript code snippets

Find secure code to use in your application or website