mercredi 23 septembre 2015

Access instance methods in a component wrapped in a Higher Order Component - React.js

I am writing some tests for my React component:

let DebugElement = TestUtils.renderIntoDocument(<Debug />);
console.log(DebugElement)
spyOn(DebugElement, 'fetchAndSelect');

However, it says that fetchAndSelect doesn't exist. Which is true.

I wrap my component like so:

import { DragDropContext } from 'react-dnd';

const Debug = React.createClass({
     fetchAndSelect() {}
});

export default DragDropContext(HTML5Backend)(Debug);

If you look at the screenshot below, you can see that I can access my component methods inside refs.child. Is this the right way?

enter image description here

Aucun commentaire:

Enregistrer un commentaire