Skip to content
This repository was archived by the owner on Sep 5, 2021. It is now read-only.

Test ensuring that elements inspected as they are written#26

Open
sunesimonsen wants to merge 1 commit intomasterfrom
ssimonsen/inspect-children-test
Open

Test ensuring that elements inspected as they are written#26
sunesimonsen wants to merge 1 commit intomasterfrom
ssimonsen/inspect-children-test

Conversation

@sunesimonsen
Copy link
Collaborator

This test shows that children in inspected as they are written.

@sunesimonsen
Copy link
Collaborator Author

sunesimonsen commented Mar 13, 2018

I think this shows pretty well the problem around inspecting the React elements as they are written. If I would like to assert that this structure contains the following:

expect(
  enzyme.mount(
    <ReverseChildren>
      <span>One</span>
      <span>Two</span>
      <span>Three</span>
    </ReverseChildren>
  ),
  'to contain',
  <div>
    <span>Three</span>
    <span>Two</span>
    <span>One</span>
  </div>
);

This passes.

But if we make it fail:

expect(
  enzyme.mount(
    <ReverseChildren>
      <span>One</span>
      <span>Two</span>
      <span>Three</span>
    </ReverseChildren>
  ),
  'to contain',
  <div>
    <span>Three</span>
    <span>Two!</span>
    <span>One</span>
  </div>
);

You get this:

expected
<ReverseChildren>
  <span>One</span>
  <span>Two</span>
  <span>Three</span>
</ReverseChildren>
to contain <div><span>Three</span><span>Two!</span><span>One</span></div>

the best match was
One // should be <div><span>Three</span><span>Two!</span><span>One</span></div>

That is really unhelpful :-S

I would much prefer something like this instead:

expected <div><span>Three</span><span>Two</span><span>One</span></div> to contain
<div>
  <span>Three</span>
  <span>Two!</span>
  <span>One</span>
</div>

<div>
  <span>Three</span>
  <span>
    Two // should equal 'Two!'
        //
        // Two
        // Two!
  </span>
  <span>One</span>
</div>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant