Reactjs prop与prop查询一起处于未渲染状态

Reactjs prop与prop查询一起处于未渲染状态,reactjs,enzyme,Reactjs,Enzyme,我有以下单元测试: const wrap = (props = {}) => shallow(<Col {...props} />).dive(); describe('Col', () => { it('should render a 100% wide div by default', () => { const wrapper = wrap(); console.log(wrapper.unrendered.props); ex

我有以下单元测试:

const wrap = (props = {}) => shallow(<Col {...props} />).dive();

describe('Col', () => {
  it('should render a 100% wide div by default', () => {
    const wrapper = wrap();

    console.log(wrapper.unrendered.props);
    expect(wrapper.props().w).toBe(1);
    expect(wrapper.type().target).toBe('div');
因此,我要测试的
w
属性位于
shallowRapper
的一个名为
unrendered
的属性中,但不在包装器中


我对这个未渲染的对象是什么以及为什么该属性不在包装器上感到困惑。

未渲染的对象只是ShallowRapper的实现细节。您可以通过检查ShallowRapper:的源来查看它的使用方式

如果要测试特定的prop
w
,请使用props()API:

您已经在日志
未渲染的行下方的代码行中执行了此操作。为了测试您的组件,不要担心包装器的实现细节(当然也不要编写挖掘未描述的测试,因为实现细节可能会发生更改)。相反,依赖于公共API(在本例中是
props()
方法)

  ShallowWrapper {
    root: [Circular],
    unrendered:
     { '$$typeof': Symbol(react.element),
       type:
        { [Function: StyledComponent]
          withComponent: [Function: withComponent],
          contextTypes: [Object],
          displayName: 'styled.div',
          styledComponentId: 'sc-ifAKCX',
          attrs: undefined,
          componentStyle: [Object],
          warnTooManyClasses: [Function],
          target: 'div' },
       key: null,
       ref: null,
       props: { w: 1, children: undefined },
       _owner: null,
       _store: {} },