Reactjs: How To Test For A Ref?
This is a function used in a react component. As you can see I'm using ref to get the focus on a specific input element of another component. myFunction (param) { this.refInput &
Solution 1:
Try doing something like this:
it('myFunction() should call focus()', () => {
// SETUP
wrapper = mount(<Example />)
// EXECUTE
wrapper.instance().myFunction('anything')
// VERIFYconst elem = wrapper.find('#foo');
const focusedElement = document.activeElement;
expect(elem.matchesElement(focusedElement)).to.equal(true);
})
Points to note:
Post a Comment for "Reactjs: How To Test For A Ref?"