Skip to content

Shallow render components #12

@k-ode

Description

@k-ode

One of the nice things about testing React components with Enzyme is that you can test your components as shallow. In this case, only the top level component gets rendered and all child components are ignored. This makes a lot of sense for unit testing, since you want to test your components as small, independent parts.

It would be nice if you could just call renderShallowComponent(...), but I'm guessing that would also be really involved. I can't say I have any idea how this would be implemented, maybe override the component binding somehow?

A simpler method would be an option to ignore certain components. So if you have a TodoList you could do:

renderComponent({
    viewModel: TodoList,
    template: todoListTemplate,
    ignoreComponents: ['Todo']
})

These sub components would be registered as empty components. This is what I currently do in a before-call, but it would be tidier to have the functionality built in.

Thoughts?

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