Skip to content

Allow depth option when serializing mounted wrappers #169

@iamogbz

Description

@iamogbz

Description

Sometimes you have to mount a component for it too fully render e.g. in the case of functional components. However when snapshotting the rendered enzyme wrapper, you do not need the entire tree.

Currently there are two options deep and shallow. Deep does the entire tree which most times is not what you want to snapshot. Shallow only serializes the initial component instance.

Adding the ability to specify depth would be great for cases where you need to only snapshot to a certain level of granularity.

Depth Description
0 Equivalent to mode: shallow
1 Equivalent to shallow render
..
Infinity Equivalent to mode: deep

Note

Workarounds do exist e.g.

const serialized = toJson(wrapper.find(Base).children(), { mode: 'shallow' })
expect(serialized).toMatchSnapshot()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions