Skip to content

Documentation issue, mount -> update #2494

Open
@anton-johansson

Description

Hi! I'm just getting started with Enzyme, and I think it looks great so far.

I think I've come across a documentation issue. I work with TypeScript, and when I look at the method update() of the return value of mount(...), like this:

const document = mount(<div>test</div>);
document.update();

The documentation in my IDE says the following:

    /**
     * Forces a re-render. Useful to run before checking the render output if something external may be updating
     * the state of the component somewhere.
     * Returns itself.
     *
     * NOTE: can only be called on a wrapper instance that is also the root instance.
     */

However, if I look at this page, it says:

Syncs the enzyme component tree snapshot with the react component tree.

If the latter is correct, this is definitely the function I'm looking for. I do have something external that is updating the state, so synchronizing the trees makes sense. If the former is correct, it's absolutely not something I want to do, because I feel like forcing a re-render breaks the integrity of the test. It should re-render on its own if everything is in order.

I hope you understand what I'm saying here, and I'd appreciate any answer that could indicate which of the documentation is correct (or if I'm looking at two different documentations completely!).

Activity

mrdulin

mrdulin commented on Apr 22, 2022

@mrdulin

The document of .update() method needs more clearly.

something external may be updating the state of the component somewhere

What does "something external" means?

ljharb

ljharb commented on Apr 22, 2022

@ljharb
Member

JavaScript outside of your test.

mrdulin

mrdulin commented on Apr 22, 2022

@mrdulin

@ljharb Sorry, still don't understand. There is an example in the doc .update() => Self.

The example uses a class component with the property count. How is this "something external"? I spent 2 minutes reading the source code of the .update method, the intent is not easy to understand.

Is there any other scenario considered as "something external"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Documentation issue, mount -> update · Issue #2494 · enzymejs/enzyme