JavaScript Testing utilities for React

Overview

Enzyme

Join the chat at https://gitter.im/enzymejs/enzyme

npm Version License Build Status Coverage Status

Enzyme is a JavaScript Testing utility for React that makes it easier to test your React Components' output. You can also manipulate, traverse, and in some ways simulate runtime given the output.

Enzyme's API is meant to be intuitive and flexible by mimicking jQuery's API for DOM manipulation and traversal.

Upgrading from Enzyme 2.x or React < 16

Are you here to check whether or not Enzyme is compatible with React 16? Are you currently using Enzyme 2.x? Great! Check out our migration guide for help moving on to Enzyme v3 where React 16 is supported.

Installation

To get started with enzyme, you can simply install it via npm. You will need to install enzyme along with an Adapter corresponding to the version of react (or other UI Component library) you are using. For instance, if you are using enzyme with React 16, you can run:

npm i --save-dev enzyme enzyme-adapter-react-16

Each adapter may have additional peer dependencies which you will need to install as well. For instance, enzyme-adapter-react-16 has peer dependencies on react and react-dom.

At the moment, Enzyme has adapters that provide compatibility with React 16.x, React 15.x, React 0.14.x and React 0.13.x.

The following adapters are officially provided by enzyme, and have the following compatibility with React:

Enzyme Adapter Package React semver compatibility
enzyme-adapter-react-16 ^16.4.0-0
enzyme-adapter-react-16.3 ~16.3.0-0
enzyme-adapter-react-16.2 ~16.2
enzyme-adapter-react-16.1 ~16.0.0-0 || ~16.1
enzyme-adapter-react-15 ^15.5.0
enzyme-adapter-react-15.4 15.0.0-0 - 15.4.x
enzyme-adapter-react-14 ^0.14.0
enzyme-adapter-react-13 ^0.13.0

Finally, you need to configure enzyme to use the adapter you want it to use. To do this, you can use the top level configure(...) API.

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

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

3rd Party Adapters

It is possible for the community to create additional (non-official) adapters that will make enzyme work with other libraries. If you have made one and it's not included in the list below, feel free to make a PR to this README and add a link to it! The known 3rd party adapters are:

Adapter Package For Library Status
enzyme-adapter-preact-pure preact (stable)
enzyme-adapter-inferno inferno (work in progress)

Running Enzyme Tests

Enzyme is unopinionated regarding which test runner or assertion library you use, and should be compatible with all major test runners and assertion libraries out there. The documentation and examples for enzyme use Mocha and Chai, but you should be able to extrapolate to your framework of choice.

If you are interested in using enzyme with custom assertions and convenience functions for testing your React components, you can consider using:

Using Enzyme with Mocha

Using Enzyme with Karma

Using Enzyme with Browserify

Using Enzyme with SystemJS

Using Enzyme with Webpack

Using Enzyme with JSDOM

Using Enzyme with React Native

Using Enzyme with Jest

Using Enzyme with Lab

Using Enzyme with Tape and AVA

Basic Usage

Shallow Rendering

import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import sinon from 'sinon';

import MyComponent from './MyComponent';
import Foo from './Foo';

describe('<MyComponent />', () => {
  it('renders three <Foo /> components', () => {
    const wrapper = shallow(<MyComponent />);
    expect(wrapper.find(Foo)).to.have.lengthOf(3);
  });

  it('renders an `.icon-star`', () => {
    const wrapper = shallow(<MyComponent />);
    expect(wrapper.find('.icon-star')).to.have.lengthOf(1);
  });

  it('renders children when passed in', () => {
    const wrapper = shallow((
      <MyComponent>
        <div className="unique" />
      </MyComponent>
    ));
    expect(wrapper.contains(<div className="unique" />)).to.equal(true);
  });

  it('simulates click events', () => {
    const onButtonClick = sinon.spy();
    const wrapper = shallow(<Foo onButtonClick={onButtonClick} />);
    wrapper.find('button').simulate('click');
    expect(onButtonClick).to.have.property('callCount', 1);
  });
});

Read the full API Documentation

Full DOM Rendering

import React from 'react';
import sinon from 'sinon';
import { expect } from 'chai';
import { mount } from 'enzyme';

import Foo from './Foo';

describe('<Foo />', () => {
  it('allows us to set props', () => {
    const wrapper = mount(<Foo bar="baz" />);
    expect(wrapper.props().bar).to.equal('baz');
    wrapper.setProps({ bar: 'foo' });
    expect(wrapper.props().bar).to.equal('foo');
  });

  it('simulates click events', () => {
    const onButtonClick = sinon.spy();
    const wrapper = mount((
      <Foo onButtonClick={onButtonClick} />
    ));
    wrapper.find('button').simulate('click');
    expect(onButtonClick).to.have.property('callCount', 1);
  });

  it('calls componentDidMount', () => {
    sinon.spy(Foo.prototype, 'componentDidMount');
    const wrapper = mount(<Foo />);
    expect(Foo.prototype.componentDidMount).to.have.property('callCount', 1);
    Foo.prototype.componentDidMount.restore();
  });
});

Read the full API Documentation

Static Rendered Markup

import React from 'react';
import { expect } from 'chai';
import { render } from 'enzyme';

import Foo from './Foo';

describe('<Foo />', () => {
  it('renders three `.foo-bar`s', () => {
    const wrapper = render(<Foo />);
    expect(wrapper.find('.foo-bar')).to.have.lengthOf(3);
  });

  it('renders the title', () => {
    const wrapper = render(<Foo title="unique" />);
    expect(wrapper.text()).to.contain('unique');
  });
});

Read the full API Documentation

React Hooks support

Enzyme supports react hooks with some limitations in .shallow() due to upstream issues in React's shallow renderer:

  • useEffect() and useLayoutEffect() don't get called in the React shallow renderer. Related issue

  • useCallback() doesn't memoize callback in React shallow renderer. Related issue

ReactTestUtils.act() wrap

If you're using React 16.8+ and .mount(), Enzyme will wrap apis including .simulate(), .setProps(), .setContext(), .invoke() with ReactTestUtils.act() so you don't need to manually wrap it.

A common pattern to trigger handlers with .act() and assert is:

const wrapper = mount(<SomeComponent />);
act(() => wrapper.prop('handler')());
wrapper.update();
expect(/* ... */);

We cannot wrap the result of .prop() (or .props()) with .act() in Enzyme internally since it will break the equality of the returned value. However, you could use .invoke() to simplify the code:

const wrapper = mount(<SomeComponent />);
wrapper.invoke('handler')();
expect(/* ... */);

Future

Enzyme Future

Contributing

See the Contributors Guide

In the wild

Organizations and projects using enzyme can list themselves here.

License

MIT

Comments
  • Add support for react context element types, fixes #1509

    Add support for react context element types, fixes #1509

    There are some outstanding support concerns here with shallow rendered per https://github.com/facebook/react/issues/12152 but i wasn't attempting to fix those here. This just adds support for traversal over said elements. I was not sure how to structure the peer deps in a way that would exercise this test as well...

    cc @aweary

    semver: minor package: react adapter: 16 
    opened by jquense 89
  • Testing a Redux-connected component using Enzyme

    Testing a Redux-connected component using Enzyme

    Enzyme

    i) What is the least error-prone way to test a Redux-connected Componet using Enzyme? I have checked many links and articles but haven't found a satisfactory answer. It's confusing me a lot. ii)How can I test whether my component is getting certain props or not using Enzyme?

    Versions

    • React-Boilerplate : Current Version
    • Node/NPM: ^6
    • Browser: Chrome
    • Enzyme: Current Version
    question 
    opened by mrsaeeddev 80
  • Testing Hooks with shallow: Invariant Violation

    Testing Hooks with shallow: Invariant Violation

    Current behavior

    When testing component which contains newly released React Hooks using shallow, it crashes: Invariant Violation: Hooks can only be called inside the body of a function component.

    Everything works fine at run time or when testing with render:

    My test component:

    import * as React from 'react';
    
    function Test() {
        const [myState, setMyState] = React.useState('Initial state');
    
        const changeState = () => setMyState('State updated');
    
        return (
            <div>
                {myState}
                <button onClick={changeState}>Change</button>
            </div>
        );
    }
    
    export default Test;
    

    My test file:

    import { shallow } from 'enzyme';
    import * as React from 'react';
    import Test from './Test';
    
    it('renders without crashing', () => {
        const comp = shallow(<Test />);
    
        expect(comp.find('Test')).toMatchSnapshot();
    });
    

    Error stack trace:

    Invariant Violation: Hooks can only be called inside the body of a function component.
    
        at invariant (node_modules/react/cjs/react.development.js:125:15)
        at resolveDispatcher (node_modules/react/cjs/react.development.js:1450:28)
        at Object.useState (node_modules/react/cjs/react.development.js:1473:20)
        at Test (src/Test.tsx:4:11)
        at node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:440:38
        at ReactShallowRenderer.render (node_modules/react-test-renderer/cjs/react-test-renderer-shallow.development.js:412:39)
        at node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:444:37
        at withSetStateAllowed (node_modules/enzyme-adapter-utils/build/Utils.js:137:16)
        at Object.render (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:443:70)
        at new ShallowWrapper (node_modules/enzyme/build/ShallowWrapper.js:206:22)
        at Object.shallow (node_modules/enzyme/build/shallow.js:21:10)
        at Object.<anonymous> (src/Test.test.tsx:6:18)
            at new Promise (<anonymous>)
        at Promise.resolve.then.el (node_modules/p-map/index.js:46:16)
        at process._tickCallback (internal/process/next_tick.js:68:7)
    

    Expected behavior

    Tests should run

    Your environment

    Fresh create-react-app-typescript install with react 16.7.0-alpha-0

    API

    • [x] shallow
    • [ ] mount
    • [ ] render

    Version

    | library | version | ------------------- | ------- | enzyme | 3.8.0 | react | 16.7.0-alpha.0 | react-dom | 16.7.0-alpha.0 | react-test-renderer | | adapter (below) |

    Adapter

    • [x] enzyme-adapter-react-16
    • [ ] enzyme-adapter-react-16.3
    • [ ] enzyme-adapter-react-16.2
    • [ ] enzyme-adapter-react-16.1
    • [ ] enzyme-adapter-react-15
    • [ ] enzyme-adapter-react-15.4
    • [ ] enzyme-adapter-react-14
    • [ ] enzyme-adapter-react-13
    • [ ] enzyme-adapter-react-helper
    • [ ] others ( )
    opened by TdyP 79
  • Support React.lazy and React.Suspense

    Support React.lazy and React.Suspense

    Fixes #1917 .

    Given a component wrapped by React.lazy in <Suspense /> It'll plainly render a <Lazy /> in shallow and render fallback component in mount.

    There are something I'm not sure / still working on:

    1. What should displayName of the component returned by React.lazy be? Currently I directly named it as Lazy. Not sure if it's something we could define by ourselves.

    2. I'm trying to add an waitUntilLazyLoaded() on ReactWrapper, which will return a promise resolving when the dynamic import loaded and React trigger the re-render, so we can write some tests like:

    
    const LazyComponent = lazy(() => import('/path/to/dynamic/component'));
    const Fallback = () => <div />;
    const SuspenseComponent = () => (
        <Suspense fallback={<Fallback />}>
          <LazyComponent />
        </Suspense>
    );
    
    const wrapper = mount(<SuspenseComponent />)
    await wrapper.waitUntilLazyLoaded()
    
    expect(wrapper.find('DynamicComponent').to.have.lengthOf(1)
    
    

    But I don't know how to detect if all the lazy loaded component inside <Suspense /> has completeted loading. It looks like that we have to hack around react fiber. @ljharb Would you know any way to detect this?

    Also note that this PR add babel-plugin-dynamic-import-node and babel-plugin-syntax-dynamic-import for using import(), babel-eslint in enzyme-adapter-react-16 and enzyme-test-suite for dynamic import support of eslint.

    API: shallow API: mount semver: minor package: react adapter: 16 
    opened by chenesan 74
  • Setting text value of input

    Setting text value of input

    To set the value of an input currently I have to do:

    const form = mount(<MyComponent />);
    const input = form.find('input').get(0);
    input.value = 'Blah blah';
    

    It would be really nice in my opinion if I could instead do something akin to jQuery:

    form.find('input').text('Blah blah')
    // or probably better
    form.find('input').value('Blah blah')
    

    What are your thoughts on that? I'd be happy to attempt to work on the PR :)

    enhancement help wanted 
    opened by jackfranklin 74
  • Webpack build issues

    Webpack build issues

    I'm trying to get enzyme working using a pretty standard webpack/karma setup. Webpack throws a bunch of errors related to the dependencies enzyme imports, including sinon, cheerio, and jsdom. Sinon gives webpack heartburn because it uses it's own require (which seems to be documented here: https://github.com/webpack/webpack/issues/304), and then there are a bunch of "Module not found" errors for jsdom and cheerio.

    I'm importing enzyme as described in the docs and can't really think of anything else I might be missing, so I'm curious if anyone else is trying to use webpack and running into a similar issue, or if there's just something weird with my configuration. I'd expect to be able to just import it and have it work, but maybe I need to do something with those external libraries?

    Here's my test file for reference:

    import expect from 'expect';
    import { shallow } from 'enzyme';
    import React from 'react';
    import Button from '../Button';
    
    describe('Button', () => {
        it('should render children passed in', () => {
            const wrapper = shallow(
                <Button><div className="foo" /></Button>
            );
    
            expect(wrapper.contains(<div className="foo" />)).toBe(true);
        });
    });
    

    I won't paste the entire error log from webpack because it's pretty long, but here's a sample:

    
    WARNING in ./~/enzyme/~/jsdom/~/acorn/dist/acorn.js
    Critical dependencies:
    1:478-485 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
     @ ./~/enzyme/~/jsdom/~/acorn/dist/acorn.js 1:478-485
    
    WARNING in ./~/enzyme/~/jsdom/~/acorn/dist/walk.js
    Critical dependencies:
    1:503-510 This seems to be a pre-built javascript file. Though this is possible, it's not recommended. Try to require the original source to get better results.
     @ ./~/enzyme/~/jsdom/~/acorn/dist/walk.js 1:503-510
    
    ERROR in ./~/enzyme/build/react-compat.js
    Module not found: Error: Cannot resolve module 'react/lib/ExecutionEnvironment' in /Users/agoggin/www/vhosts/hammerhead/node_modules/enzyme/build
     @ ./~/enzyme/build/react-compat.js 22:2-43
    
    ERROR in ./~/enzyme/~/cheerio/index.js
    Module not found: Error: Cannot resolve module 'json' in /Users/agoggin/www/vhosts/hammerhead/node_modules/enzyme/node_modules/cheerio
     @ ./~/enzyme/~/cheerio/index.js 11:18-38
    
    ERROR in ./~/enzyme/~/jsdom/lib/jsdom.js
    Module not found: Error: Cannot resolve module 'fs' in /Users/agoggin/www/vhosts/hammerhead/node_modules/enzyme/node_modules/jsdom/lib
     @ ./~/enzyme/~/jsdom/lib/jsdom.js 6:9-22
    

    My webpack/karma config is pretty vanilla, but it'd help I can post that, too.

    bug Environment 
    opened by kgoggin 73
  • Testing component methods

    Testing component methods

    I couldn't find any information on this, if this is a duplicate excuse me for stealing your time.

    I'm trying to test this application, but I ran into a wall when testing component methods. As an example, take this component:

    class Button extends React.Component {
      handleClick() {
        // Do something here
      }
      render() {
        // Component here
      }
    }
    

    How could I test the handleClick method here when shallowly rendering this component? (The same question applies to lifecycle methods)

    opened by mxstbr 62
  • Error: This method is only meant to be run on single node. 0 found instead.

    Error: This method is only meant to be run on single node. 0 found instead.

    Clearly rendering a node. It's not picking it up..?

    render() {
        let groceriesComponents = [],
            newProductInput,
            newProductAddButton,
            clearListButton;
    
        for(var index = 0; index < this.state.groceries.length; index++) {
          groceriesComponents.push(
              <GroceryListItem
                key={index}
                grocery={this.state.groceries[index]}
              />
          );
        }
    
        newProductInput = <input className='new-item' type="text" onChange={this.inputChanged}/>;
        newProductAddButton = <button className='add-product' onClick={this.addGroceryItem}>Add new Product</button>;
        clearListButton = <button onClick={this.clearList} className='clear-list'>Clear the List</button>;
    
        return (
          <div>
            <ul>
              {groceriesComponents}
            </ul>
            {newProductInput}
            {newProductAddButton}
            {clearListButton}
          </div>
        );
      }
    }
    
    describe("Task #3 - clearing groceries list", () => {
    
        beforeEach( () => {
          component = mount(<GroceryListPart3 />);
        });
    
        it('Should render required tags', () => {
          try { component.find(".clear-list"); }
          catch(err){
            throw new Error("I can't find 'Clear the List' button");
          }
        });
    
        it('is possible to remove all list items', () => {
    
          let clearListButton = component.find(".clear-list");
          clearListButton.simulate('click');
          let groceryListItems = component.find("li");
    
          assert.equal(groceryListItems.length, 0, "There should be exactly zero elements on the groceries list");
        });
      });
    
    Error: This method is only meant to be run on single node. 0 found instead.
    
    opened by ninjasort 61
  • shallow().dive() does not work with react-redux Provider

    shallow().dive() does not work with react-redux Provider

    it('should work', () => {
      const Component = () => {
        return <div>Hello World</div>;
      };
      const wrapper = shallow(
        <Provider store={mockStore()}>
          <Component />
        </Provider>
      ).dive();
      expect(wrapper).toMatchSnapshot();
    });
    

    This is just a simple example - please assume that Component needs to have access to the react-redux context so I can use useSelector() in there, so something like .find(Component).dive() won't work

    Current behavior

    exports[`<UserMenu /> hopefully works 1`] = `<Component />`;
    

    Expected behavior

    exports[`<UserMenu /> hopefully works 1`] = `
    <div>
      Hello World
    </div>
    `;
    

    API

    • shallow

    Version

    | library | version | ------------------- | ------- | enzyme | 3.10.0 | react | 16.8.6 | react-dom | 16.8.6 | react-test-renderer | - | adapter (below) | 1.14.0

    Adapter

    • enzyme-adapter-react-16
    opened by ThiefMaster 59
  • Mount find() Does Not Find Rendered Marker

    Mount find() Does Not Find Rendered Marker

    This one is pretty frustrating. I mount this container. It does hit the code I expect that contains my css feature marker (ft-playback-error). But in the end I end up with not found.

    screencast of this issue: https://youtu.be/kh-UJTig3Qg

       it.only('renders a coordinates message in the player when no coordinates exist', () => {
          const store = createStore(reducers, {}),
    
            liveScreen = mount(
              <Provider store={createStore(reducers, {})}>
                <Live
                  breakpoint="site-web"
                  coordinates={null}
                  renderInfoInDetail={() => {}}
                  setOverlay={() => {}}
                  store={store}
                  AccessEnablerUrl=""
                  getUseUtagGlobal={() => {}}
                  pageViewEvent={() => {}}
                />
              </Provider>),
            message = liveScreen.find('.ft-playback-error');
    
          expect(message).to.have.length(1);
        });
    

    message.nodes ends up being 0 (or aka not found). Why? screen shot 2017-10-05 at 10 54 05 am

    I assumed when you mounted, it runs every child's render() (every child that's being hit down the codepath of container..obviously depending on whatever logic is in its render will determine which children are being rendered) method of this container.

    opened by dschinkel 58
  • Support React 16

    Support React 16

    React is currently in v16.0.0-alpha.12, but is it already planned to support it by enzyme? My specific issue currently is #875.

    Is it too early to implement it, as it is in alpha?

    opened by JPeer264 54
  • TypeError: window.require is not a function

    TypeError: window.require is not a function

    Thanks for reporting an issue to us! We're glad you are using and invested in Enzyme. Before submitting, please read over our commonly reported issues to prevent duplicates!

    All common issues

    Notoriously common issues

    If you haven't found any duplicated issues, please report it with your environment!

    Current behavior

    When testing my project, I get this error with the mount() function: image

        TypeError: window.require is not a function
    
          57 |         };
          58 |
        > 59 |         const wrapper = mount(<HealthStatusAnchor healthStatus={health} resourceId={resourceId} isImpactedEnabled={isIREnabled}/> );
             |                         ^
          60 |
          61 |         wrapper.find('button').simulate('click');
          62 |         expect(openBladeSpy).toHaveBeenCalledTimes(1);
    
          at Object.getErrorBoundary (node_modules/azureportal-reactview/src/internal/ErrorBoundary.tsx:206:33)
          at _FrameworkIcon (node_modules/azureportal-reactview/src/FrameworkIcon.tsx:51:27)
          at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:14803:18)
          at mountIndeterminateComponent (node_modules/react-dom/cjs/react-dom.development.js:17482:13)
          at beginWork (node_modules/react-dom/cjs/react-dom.development.js:18596:16)
          at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:188:14)
          at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
          at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
          at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
          at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
          at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
          at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
          at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:237:16)
          at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:292:31)
          at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:23203:7)
          at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:22157:12)
          at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:22130:22)
          at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:21756:9)
          at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:21188:7)
          at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:24373:3)
          at node_modules/react-dom/cjs/react-dom.development.js:24758:7
          at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:21903:12)
          at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:24757:5)
          at Object.render (node_modules/react-dom/cjs/react-dom.development.js:24840:10)
          at fn (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:488:26)
          at node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:405:37
          at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:21856:12)
          at Object.act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:929:14)
          at wrapAct (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:405:13)
          at Object.render (node_modules/enzyme-adapter-react-16/src/ReactSixteenAdapter.js:474:16)
          at new ReactWrapper (node_modules/enzyme/src/ReactWrapper.js:115:16)
          at Object.mount (node_modules/enzyme/src/mount.js:10:10)
          at Object.<anonymous> (components/common/__tests__/HealthStatusAnchor.spec.tsx:59:25)
    

    Expected behavior

    This test was running before, but after running yarn install, some of our other dependencies were updated and now the mount() function is throwing errors. We're not sure why this might be happening, since the relation between these updates and the new error is not clear. Does anyone know why this is happening?

    Your environment

    API

    • [ ] shallow
    • [x] mount
    • [ ] render

    Version

    | library | version | ------------------- | ------- | enzyme | 3.11.0 | react | 16.14.0 | react-dom | 16.14.0 | react-test-renderer | 16.14.0 | adapter (below) |

    Adapter

    • [x] enzyme-adapter-react-16
    • [ ] enzyme-adapter-react-16.3
    • [ ] enzyme-adapter-react-16.2
    • [ ] enzyme-adapter-react-16.1
    • [ ] enzyme-adapter-react-15
    • [ ] enzyme-adapter-react-15.4
    • [ ] enzyme-adapter-react-14
    • [ ] enzyme-adapter-react-13
    • [ ] enzyme-adapter-react-helper
    • [ ] others ( )
    Need More Information 
    opened by cwu-ms 5
  • Method “props” is only meant to be run on a single node. 0 found instead.

    Method “props” is only meant to be run on a single node. 0 found instead.

    Method “props” is meant to be run on 1 node. 0 found instead.

     const commentTextInput = findByTestAttr(wrapper, 'clockings-add-comment');  
    
    console.log("testing1:"+commentTextInput.props().spellcheck)
    
    

    Thanks for reporting an issue to us! We're glad you are using and invested in Enzyme. Before submitting, please read over our commonly reported issues to prevent duplicates!

    All common issues

    Notoriously common issues

    If you haven't found any duplicated issues, please report it with your environment!

    Current behavior

    Expected behavior

    Your environment

    API

    • [x] shallow
    • [ ] mount
    • [ ] render

    Version

    | library | version | ------------------- | ------- | enzyme | | react | | react-dom | | react-test-renderer | | adapter (below) |

    Adapter

    • [ ] enzyme-adapter-react-16
    • [ ] enzyme-adapter-react-16.3
    • [ ] enzyme-adapter-react-16.2
    • [ ] enzyme-adapter-react-16.1
    • [ ] enzyme-adapter-react-15
    • [ ] enzyme-adapter-react-15.4
    • [ ] enzyme-adapter-react-14
    • [ ] enzyme-adapter-react-13
    • [ ] enzyme-adapter-react-helper
    • [ ] others ( )
    Need More Information 
    opened by Pinturaj 1
  • add enzyme-adapter-react-17

    add enzyme-adapter-react-17

    Stacked on #2534 (Diff against #2534)

    Compared to https://github.com/enzymejs/enzyme/pull/2534/:

    • less React 17 branching in tests (goal is 0 branching but branching for error stacks is probably fine)
    • some legacy code removed

    TODO: Open to discussing the remaining items @ljharb

    • [ ] callstack/componentstack Would need to discuss if we want to normalize them across React versions. For the initial release I would lean towards being ok with different stacks between 16 and 17 since that's also what developers experience.
    • [x] hide internal Suspense fibers
    • [x] Green CI
    • [x] code coverage hygiene

    Closes https://github.com/enzymejs/enzyme/issues/2429 Closes https://github.com/enzymejs/enzyme/pull/2534 Closes https://github.com/enzymejs/enzyme/pull/2430

    opened by eps1lon 13
  • Cannot read property 'child' of undefined on React 16 + enzyme-adapter-react-16

    Cannot read property 'child' of undefined on React 16 + enzyme-adapter-react-16

    Current behavior

    import React from "react";
    import { mount } from "enzyme";
    import NewTagModal from "./NewTagModal";
    
    describe("New Tag Modal", () => {
      let component;
      function mountComponent() {
        return mount(
          <NewTagModal isOpen={true} />;
        );
      }
    
      beforeEach(() => {
        component = mountComponent();
      });
    
      it("has a title", () => {
        expect(component.find("h4").text()).toBe("Create New Tag");
      });
    });
    

    Returns:

        TypeError: Cannot read property 'child' of undefined
    
          72 |
          73 |   function mountComponent() {
        > 74 |     return mount(
    
          at getFiber (../../../node_modules/enzyme-adapter-react-16/src/detectFiberTags.js:15:35)
          at detectFiberTags (../../../node_modules/enzyme-adapter-react-16/src/detectFiberTags.js:76:15)
          at ReactSixtee^C
    

    Expected behavior

    Tests pass

    API

    • [ ] shallow
    • [x] mount
    • [ ] render

    Version

    | library | version | ------------------- | ------- | enzyme | 3.11.0 | react | 16.4.0 | react-dom | 16.4.0 | react-test-renderer | n/a | adapter (below) | enzyme-adapter-react-16

    Adapter

    • [x] enzyme-adapter-react-16
    • [ ] enzyme-adapter-react-16.3
    • [ ] enzyme-adapter-react-16.2
    • [ ] enzyme-adapter-react-16.1
    • [ ] enzyme-adapter-react-15
    • [ ] enzyme-adapter-react-15.4
    • [ ] enzyme-adapter-react-14
    • [ ] enzyme-adapter-react-13
    • [ ] enzyme-adapter-react-helper
    • [ ] others ( )
    Need More Information 
    opened by dep 1
  • Bump cheerio to @1.0.0-rc.11

    Bump cheerio to @1.0.0-rc.11

    Due to recent security vulnerability in nth-checkv1.2.0 which is fetched transitively from enzyme --> cheerio --> css-select --> .... --> nth-checkv1.2.0.

    [email protected] removes dependency of css-select which ultimately removes dependency of nth-check

    opened by vinodkumarsharma276 4
Owner
enzyme - JavaScript Testing utilities for React
enzyme - JavaScript Testing utilities for React
React + Redux starter kit / boilerplate with Babel, hot reloading, testing, linting and a working example app built in

A comprehensive starter kit for rapid application development using React. Why Slingshot? One command to get started - Type npm start to start develop

Cory House 9.8k Dec 22, 2022
A collection of framework specific Auth utilities for working with Supabase.

A collection of framework specific Auth utilities for working with Supabase.

Supabase Community 507 Jan 2, 2023
Set of property utilities for Stitches with theme tokens support. Use the built-in utils, or easily build custom ones.

Stitches Mix Set of property utilities for Stitches with theme tokens support. Use the built-in utils, or easily build custom ones. Usage To import al

João Pedro Schmitz 12 Aug 8, 2022
Utilities library built on top of Next.js providing feature extensions and helpers for common patterns

nextjs-utilites This library provides many helpful utilities for use in Next.js projects. Prerequisites This project requires NodeJS (version 8 or lat

Snehil K 5 Sep 7, 2022
Recoil is an experimental state management library for React apps. It provides several capabilities that are difficult to achieve with React alone, while being compatible with the newest features of React.

Recoil · Recoil is an experimental set of utilities for state management with React. Please see the website: https://recoiljs.org Installation The Rec

Facebook Experimental 18.2k Jan 8, 2023
Sandbox for developing and testing UI components in isolation

React Cosmos Sandbox for developing and testing UI components in isolation. Visual TDD. Develop one component at a time. Isolate the UI you're working

React Cosmos 7.7k Jan 3, 2023
UI for Keploy platform that does API testing by dependency mocking without writing any test cases.

Welcome to Keploy UI ?? About Us Keploy is a no-code API testing platform. Keploy automatically generates unit test cases with dependency mocks from A

Keploy Inc 23 Dec 28, 2022
High performance personalization & a/b testing example using Next.js, Edge Middleware, and Builder.io

Next.js + Builder.io Personalization & A/B Testing with Edge Middleware This is a fork of Next.js Commerce with Builder.io integrated and using Edge M

Builder.io 25 Dec 25, 2022
React Starter Kit — isomorphic web app boilerplate (Node.js, Express, GraphQL, React.js, Babel, PostCSS, Webpack, Browsersync)

React Starter Kit — "isomorphic" web app boilerplate React Starter Kit is an opinionated boilerplate for web development built on top of Node.js, Expr

Kriasoft 21.7k Dec 30, 2022
📋 React Hooks for forms validation (Web + React Native)

English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Русский | Deutsch | Türkçe Features Built with performance and DX in mind

React Hook Form 32.4k Dec 29, 2022
:black_medium_small_square:React Move | Beautiful, data-driven animations for React

React-Move Beautiful, data-driven animations for React. Just 3.5kb (gzipped)! Documentation and Examples Features Animate HTML, SVG & React-Native Fin

Steve Hall 6.5k Jan 1, 2023
React features to enhance using Rollbar.js in React Applications

Rollbar React SDK React features to enhance using Rollbar.js in React Applications. This SDK provides a wrapper around the base Rollbar.js SDK in orde

Rollbar 39 Jan 3, 2023
🎉 toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense!

toastify-react-native ?? toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense! De

Zahid Ali 29 Oct 11, 2022
Soft UI Dashboard React - Free Dashboard using React and Material UI

Soft UI Dashboard React Start your Development with an Innovative Admin Template for Material-UI and React. If you like the look & feel of the hottest

Creative Tim 182 Dec 28, 2022
A web application to search all the different countries in the world and get details about them which can include languages, currencies, population, domain e.t.c This application is built with CSS, React, Redux-Toolkit and React-Router.

A web application to search all the different countries in the world and get details about them which can include languages, currencies, population, domain e.t.c This application is built with CSS, React, Redux-Toolkit and React-Router. It also includes a theme switcher from light to dark mode.

Franklin Okolie 4 Jun 5, 2022
Finished code and notes from EFA bonus class on building a React project without create-react-app

React From Scratch Completed Code This is the completed code for the EFA bonus class on building a React project from scratch. Included are also markd

Conor Broaders 3 Oct 11, 2021
Free Open Source High Quality Dashboard based on Bootstrap 4 & React 16: http://dashboards.webkom.co/react/airframe

Airframe React High Quality Dashboard / Admin / Analytics template that works great on any smartphone, tablet or desktop. Available as Open Source as

Mustafa Nabavi 6 Jun 5, 2022
React tooltip is a React.JS Component that brings usefull UX and UI information in selected elements of your website.

React Tooltip ✅ React tooltip is a React.JS Component that brings usefull UX and UI information in elements of your website. Installation ⌨️ React Too

Marc Ramos 1 Dec 22, 2021
React-Mini-Projects - Simple React mini-applications

React Mini Projects A Fully Responsive React Application contain these mini apps : Todo App Movie App Budget App Flash Card App Factor App This app wa

Morteza Rezaienia 1 Jan 1, 2022