Enzyme: Using react-dnd for simulating drag & drop but .getHandlerId() is not a function when I update to new enzyme

Created on 8 Mar 2018  路  6Comments  路  Source: enzymejs/enzyme

Have a test which simulates drag & drop behavior which used to work in enzyme 2 but doesnt now with enzyme 3. Not too sure whats going on .

card.get(...).getHandlerId is not a function

```
const component = mount();
const card = component.find(Card);
component.instance().getManager().getBackend().simulateBeginDrag([card.get(0).getHandlerId()]);

This is the card :

{ '$$typeof': Symbol(react.element),
type:
{ [Function: DragDropContainer]
DecoratedComponent: { [Function: Card] propTypes: [Object] },
displayName: 'DragSource(Card)',
contextTypes: { dragDropManager: [Function: bound checkType] } },
key: null,
ref: null,
props:
{ _id: '111',
cellId: '11',
component:
{ '$$typeof': Symbol(react.element),
type: [Function: Template],
key: null,
ref: null,
props: {},
_owner: null,
_store: {} },
dropHandler:
{ [Function: noop]
_isMockFunction: true,
getMockImplementation: [Function],
mock: [Getter/Setter],
mockClear: [Function],
mockReset: [Function],
mockReturnValueOnce: [Function],
mockReturnValue: [Function],
mockImplementationOnce: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
mockRestore: [Function] },
_recordId: 'mocked-record',
_parentContainerId: 'mocked-parent' },
_owner: null,
_store: {}
}

API

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

Version

| library | version
| ---------------- | -------
| Enzyme | latest
| React | 15.5.4

Adapter

  • [ ] enzyme-adapter-react-16
  • [X] enzyme-adapter-react-15
  • [ ] enzyme-adapter-react-15.4
  • [ ] enzyme-adapter-react-14
  • [ ] enzyme-adapter-react-13
  • [ ] enzyme-adapter-react-helper
  • [ ] others ( )
question v3 expected difference

Most helpful comment

card.instance()?

All 6 comments

Instead of .get(0), you might want .getElement(0)? (mentioned in the migration guide)

@ljharb nope that doesnt work

card.instance()?

I鈥檓 confused; your initial example is using mount. Are you now using shallow?

@ljharb - sorry worked. I just realized that I accidentaly changed it to shallow & saw that error. Just deleted my comment before ur comment lol my bad.
Changed it back to mount & instance() works .
but it din't work with getElement() because ?

I鈥檓 mobile rn so I鈥檓 probably remembering wrong; but in v3, instance returns the node, getElement returns the React element.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ivanbtrujillo picture ivanbtrujillo  路  3Comments

timhonders picture timhonders  路  3Comments

andrewhl picture andrewhl  路  3Comments

abe903 picture abe903  路  3Comments

modemuser picture modemuser  路  3Comments