How to use enzyme - 10 common examples

To help you get started, we’ve selected a few enzyme 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 openshift / console / frontend / __tests__ / components / utils / promise-component.spec.tsx View on Github external
it('sets `inProgress` to true before resolving promise', (done) => {
    let wrapper = shallow();

    const promise = new Promise((resolve) => {
      // expect(wrapper.text()).toEqual('Loading...');
      resolve(42);
      expect(wrapper.find('button').exists()).toBe(true);
      done();
    });

    wrapper = wrapper.setProps({ promise });
    wrapper.find('button').simulate('click');
  });
});
github securingsincity / react-ace / tests / src / ace.spec.js View on Github external
it("should trigger the focus on mount", () => {
      const onFocusCallback = sinon.spy();
      mount(, mountOptions);

      // Read the focus
      expect(onFocusCallback.callCount).to.equal(1);
    });
github palantir / blueprint / packages / test-commons / src / generateIsomorphicTests.ts View on Github external
function render(name: string, extraProps?: object) {
        const { children, props }: IIsomorphicTestConfig = config[name] || {};
        const finalProps = extraProps ? { ...props, ...extraProps } : props;
        // Render to static HTML, just as a server would.
        // We care merely that `render()` succeeds: it can be server-rendered.
        // Errors will fail the test and log full stack traces to the console. Nifty!
        const element = React.createElement(Components[name], finalProps, children);
        return Enzyme.render(element);
    }
github react-bootstrap / react-bootstrap / test / index.js View on Github external
Enzyme.configure({ adapter: new Adapter() });

function assertLength(length) {
  return function $assertLength(selector) {
    let result = this.find(selector);
    expect(result).to.have.length(length);
    return result;
  };
}

ReactWrapper.prototype.assertSingle = assertLength(1);
ShallowWrapper.prototype.assertSingle = assertLength(1);

ReactWrapper.prototype.assertNone = assertLength(0);
ShallowWrapper.prototype.assertNone = assertLength(0);

beforeEach(() => {
  /* eslint-disable no-console */
  sinon.stub(console, 'error').callsFake(msg => {
    let expected = false;

    console.error.expected.forEach(about => {
      if (msg.indexOf(about) !== -1) {
        console.error.warned[about] = true;
        expected = true;
      }
    });

    if (expected) {
      return;
    }
github react-bootstrap / react-bootstrap / test / index.js View on Github external
import deprecated from 'prop-types-extra/lib/deprecated';

import { _resetWarned } from '../src/utils/deprecationWarning';

Enzyme.configure({ adapter: new Adapter() });

function assertLength(length) {
  return function $assertLength(selector) {
    let result = this.find(selector);
    expect(result).to.have.length(length);
    return result;
  };
}

ReactWrapper.prototype.assertSingle = assertLength(1);
ShallowWrapper.prototype.assertSingle = assertLength(1);

ReactWrapper.prototype.assertNone = assertLength(0);
ShallowWrapper.prototype.assertNone = assertLength(0);

beforeEach(() => {
  /* eslint-disable no-console */
  sinon.stub(console, 'error').callsFake(msg => {
    let expected = false;

    console.error.expected.forEach(about => {
      if (msg.indexOf(about) !== -1) {
        console.error.warned[about] = true;
        expected = true;
      }
    });
github sheinsight / shineout / test / src / Select / Select.clearable.spec.js View on Github external
test('should have clear button & clear value', () => {
    const wrapper = mount(<select>)
    expect(wrapper.find(`.${SO_PREFIX}-select-close`).length).toBe(1)
    // clear value
    wrapper.find(`.${SO_PREFIX}-select-close`).simulate('click')
    expect(wrapper.find('Select').prop('value')).toBeUndefined()
  })
  test('should have clear button &amp; clear value on multiple select', () =&gt; {</select>
github isogon / styled-mdl / tests / _setup / until.js View on Github external
return wrapper
  }
  //
  // console.log(wrapper.getElement().type);
  // console.log(selector);

  return selector && wrapper.is(selector)
    ? wrapper.dive()
    : shallowRecursively(wrapper.dive(), selector)
}

function until(selector) {
  return this.single('until', () => shallowRecursively(this, selector))
}

ShallowWrapper.prototype.until = until
github uxcore / uxcore-steps / tests / Steps.spec.js View on Github external
/* eslint-disable react/jsx-filename-extension */

import expect from 'expect.js';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import assign from 'object-assign';
import Steps from '../src';

Enzyme.configure({ adapter: new Adapter() });

const generateSteps = (options = {}) =&gt; {
  const opts = assign({}, {
    current: 1,
    direction: '',
    showIcon: true,
    type: 'default', // default title-on-top or long-desc
  }, options || {});
  const items = ['hello', 'hi', 'wola'].map((i) =&gt; {
    if (i === 'wola') {
      return ;
    }

    return ;
  });
  const wrapper = mount(
github instructure / instructure-ui / tests / util / testbed.js View on Github external
ReactWrapper.prototype.getKey = function () {
  return this.key()
}

ReactWrapper.prototype.getComputedStyle = function () {
  const domNode = this.getDOMNode()
  return domNode && window && window.getComputedStyle(domNode)
}

ReactWrapper.prototype.tagName = function () {
  const domNode = this.getDOMNode()
  return domNode && domNode.tagName.toUpperCase()
}

ReactWrapper.prototype.findText = function (text) {
  return this.findWhere(n => n.text() === text)
}

ReactWrapper.prototype.getA11yViolations = function (options, callback) {
  checkA11y(this.getDOMNode(), options, callback)
}

const originalRef = ReactWrapper.prototype.ref
ReactWrapper.prototype.ref = function () {
  const ref = arguments[0]
  const instance = this.instance()
  // eslint-disable-next-line no-prototype-builtins
  if (instance.hasOwnProperty(ref)) {
    return new ReactWrapper(instance[ref], true)
  } else {
    return originalRef.apply(this, arguments)
github instructure / instructure-ui / packages / ui-testbed / lib / enzymeWrapper.js View on Github external
}

ReactWrapper.prototype.tagName = function () {
  const domNode = this.getDOMNode()
  return domNode && domNode.tagName.toUpperCase()
}

ReactWrapper.prototype.findText = function (text) {
  return this.findWhere(n => n.text() === text)
}

ReactWrapper.prototype.findElementWithText = function (type, text) {
  return this.findWhere(n => n.type() === type && n.text() === text)
}

const originalRef = ReactWrapper.prototype.ref
ReactWrapper.prototype.ref = function () {
  const ref = arguments[0]
  const instance = this.instance()
  // eslint-disable-next-line no-prototype-builtins
  if (instance.hasOwnProperty(ref)) {
    return new ReactWrapper(instance[ref], true)
  } else if (typeof originalRef === 'function') {
    return originalRef.apply(this, arguments)
  }
}

module.exports = {
  ReactWrapper,
  mount
}