Javascript 访问封装在高阶组件(React.js)中的组件中的实例方法

Javascript 访问封装在高阶组件(React.js)中的组件中的实例方法,javascript,testing,reactjs,jasmine,Javascript,Testing,Reactjs,Jasmine,我正在为我的React组件编写一些测试: let DebugElement = TestUtils.renderIntoDocument(<Debug />); console.log(DebugElement) spyOn(DebugElement, 'fetchAndSelect'); let tree = TestUtils.renderIntoDocument(<Debug />); let DebugElement = TestUtils.findRender

我正在为我的React组件编写一些测试:

let DebugElement = TestUtils.renderIntoDocument(<Debug />);
console.log(DebugElement)
spyOn(DebugElement, 'fetchAndSelect');
let tree = TestUtils.renderIntoDocument(<Debug />);
let DebugElement = TestUtils.findRenderedComponentWithType(
  tree, Debug.DecoratedComponent
);
console.log(DebugElement)
spyOn(DebugElement, 'fetchAndSelect');
如果您查看下面的屏幕截图,可以看到我可以在
refs.child
中访问我的组件方法。这条路对吗


包装的组件实例是通过
getDecoratedComponentInstance()提供的。

有关更多信息,请参阅

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