Skip to content

Provide access to the "unrendered" element #2544

@Andarist

Description

@Andarist

Is your feature request related to a problem? Please describe.

For serialization purposes (like when working with jest serializer) I'd like to omit some internal elements rendered by component:

const Greeting = ({ children, className }) => (
  <div className={className}>{children}</div>
)
const wrapper = shallow(<Greeting css={{ backgroundColor: 'red' }}>Hello</Greeting>)

expect(wrapper).toMatchSnapshot()

Note that in the context of the serializer plugin I only have access to the ShallowWrapper's instance here. This wrapper renders smth like:

<Fragment>
  <SomethingInternal/>
  <Greeting
    className="emotion-0"
  >
    Hello
  </Greeting>
</Fragment>

And this is what I have direct access to on the wrapper. I would really like to serialize this as:

<Greeting
  className="emotion-0"
>
  Hello
</Greeting>

To avoid handling this in a false-positive manner I really need to know what element has led to this render. This is available as "unrendered" internally but this is not exposed publicly.

Describe the solution you'd like

It would be sufficient if you'd be open to adding a method like unrendered (or similar) to the API.

Describe alternatives you've considered

N/A

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions