Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing with Enzyme rather than React TestUtils #925

Closed
dwjohnston opened this issue Nov 26, 2017 · 3 comments
Closed

Testing with Enzyme rather than React TestUtils #925

dwjohnston opened this issue Nov 26, 2017 · 3 comments
Labels

Comments

@dwjohnston
Copy link

I'm getting on with writing some tests, following this documentation and also this issue #453

The problem I have is regarding the test rendering.

I can get the example that the documentation gives working, wrapping the component in a DragDropContext and rendering it with TestUtils.renderIntoDocument.

This will return a DragDropContextContainer object.

However, if I try use the Enyzme mount method to render the object, it returns a $$typeof: Symbol(react.element) object - which won't let me get the manager.

I would prefer to use Enzyme - as that's what I'm using for my tests elsewhere.

Anyone got any help with this?

@FreeMasen
Copy link

I just got this working, here is what it looks like. in typescript.

import { ThingIAmTesting } from '../file/where/it/lives';
describe('It is a test!', () => {
  let props;
  let component;
  const getComponent = () => {
    let OriginalComponent = (ThingIAmTesting as any).DecoratedComponent;
    let identity = el => el;
    if (!component) {
      component = Enzyme.shallow(
        <OriginalComponent {...props} connectDragSource={identity} />
       );
      return component
    }

    beforeEach (() => {
      props = {
         prop: 'stuff',
         }
      component = undefined;
     })
    it('should render', () => {
      let component = getComponent();
      expect(component).toMatchSnapshot();
    });
})

@gilleswittenberg
Copy link

Ran into this same problem. I could, and expect you should be able to, fix it using the wrapper.instance() method. Also described here #488.

e.g.

const Context = wrapInTestContext(Component)
const wrapper = mount(<Context />)
const manager = wrapper.instance().getManager()
const backend = manager.getBackend()

Additionally, I also needed to get the instances of child components to call getHandlerId().

If it helps, here is one of my test files: https://gist.github.com/gilleswittenberg/142fe49e1115b5a1936562b2284e1ab7

@stale
Copy link

stale bot commented Jul 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 6, 2019
@stale stale bot closed this as completed Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants