Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider allowing an object spec diff that includes the use of children #5

Open
alexjeffburke opened this issue Sep 29, 2018 · 1 comment

Comments

@alexjeffburke
Copy link
Member

alexjeffburke commented Sep 29, 2018

The use of unexpected-dom internally means the power of it's object based diff is available. I've seen a few cases where this is very useful, like being able to check the value attribute of an input after adding an event etc.

All of that works, but I discovered some arguably more corner cases in children. Namely, I went to write test using the object spec diff and wanted to have certain children ignore - so I went for the following:

          expect(
            <Hello className="World">Jane Doe</Hello>,
            "when mounted",
            "to satisfy",
            {
              children: [
                <Ignore />,
                <div data-test="value">
                  <Ignore />
                </div>
              ]
            }
          );

Note that currently the does not work for two reasons. The first, is the recent PR opened against unexpected-dom (unexpectedjs/unexpected-dom#219). The second, is that react elements in that array will not be converted mounted and rendered before the comparison. So, currently if you npm link in the PR you need to do:

          expect(
            <Hello className="World">Jane Doe</Hello>,
            "when mounted",
            "to satisfy",
            {
              children: [
                mount(<Ignore />),
                mount(
                  <div data-test="value">
                    <Ignore />
                  </div>
                )
              ]
            }
          );
@sunesimonsen
Copy link
Member

sunesimonsen commented Oct 2, 2018

I think it is a fair feature request and probably pretty doable. You just need to make a new to satisfy assertion on DOMElement against an object. Then you traverse the object and mount all JSX and hand it over to unexpected-dom. The most work would be in writing the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants