Reactjs 反应测试:浅层渲染-getRenderOutput返回null
我刚刚开始使用react测试,尝试使用浅层渲染 我不知道这里发生了什么-我相信我的代码遵循了我通过示例看到的所有说明(例如) 但是我使用Reactjs 反应测试:浅层渲染-getRenderOutput返回null,reactjs,reactjs-testutils,Reactjs,Reactjs Testutils,我刚刚开始使用react测试,尝试使用浅层渲染 我不知道这里发生了什么-我相信我的代码遵循了我通过示例看到的所有说明(例如) 但是我使用shallowrender.getRenderOutput()得到null 另外,我很困惑,因为当我注销Shallwrender时,我没有看到任何getRenderOutput方法 从“React/addons”导入React; 从“../../components/shared/Icon.jsx”导入图标; const TestUtils=React.addo
shallowrender.getRenderOutput()得到null代码>
另外,我很困惑,因为当我注销Shallwrender时,我没有看到任何getRenderOutput方法
从“React/addons”导入React;
从“../../components/shared/Icon.jsx”导入图标;
const TestUtils=React.addons.TestUtils;
函数getRenderOutput(elt){
console.log('elt:',elt);
const shallwrender=TestUtils.createRenderer();
浅层渲染器(elt);
console.log('shallwrender:',shallwrender);
const output=shallwrender.getRenderOutput();
log('output:',output);
返回输出;
}
描述(“”,()=>{
它('应该通过道具',()=>{
const result=getRenderOutput();
log('result:',result);
});
});
以及由此产生的输出:
elt:
{ type:
{ [Function: Icon]
_isMockFunction: true,
mock: { calls: [], instances: [] },
mockClear: [Function],
mockReturnValueOnce: [Function],
mockReturnValue: [Function],
mockImpl: [Function],
mockImplementation: [Function],
mockReturnThis: [Function],
_getMockImplementation: [Function],
defaultProps: { type: 'fa', classNames: '' },
propTypes:
{ type: [Object],
name: [Object],
prefix: [Object],
classNames: [Object],
title: [Object] } },
key: null,
ref: null,
_owner: null,
_context: {},
_store:
{ props:
{ type: 'octicon',
name: 'file-directory',
classNames: 'icon-roomy icon-muted' },
originalProps:
{ type: 'octicon',
name: 'file-directory',
classNames: 'icon-roomy icon-muted' } } }
shallowRenderer: { _instance:
{ _currentElement:
{ type: [Object],
key: null,
ref: null,
_owner: null,
_context: {},
_store: [Object] },
_rootNodeID: '.0',
_instance:
{ getClassNames: [Object],
render: [Object],
setState: [Object],
forceUpdate: [Object],
props: [Object],
context: {},
refs: {},
_reactInternalInstance: [Circular],
state: null },
_pendingElement: null,
_pendingStateQueue: null,
_pendingReplaceState: false,
_pendingForceUpdate: false,
_renderedComponent: { _renderedOutput: null, _currentElement: [Object] },
_context: {},
_mountOrder: 1,
_isTopLevel: false,
_pendingCallbacks: null } }
output: null
result: null
我是个白痴。我只是没有嘲笑我的组件
jest.dontMock('../../components/shared/Icon.jsx');