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

[EXPERIMENT] native inspection #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sunesimonsen
Copy link
Collaborator

Don't take this too seriously. I just wanted to see what would happen if we inspected the rendered output.

@sunesimonsen
Copy link
Collaborator Author

sunesimonsen commented Mar 13, 2018

This is pretty much how I would like things to work. I don't really care about the shallow wrapper, I would have no problem only support the full renderer.

@sunesimonsen
Copy link
Collaborator Author

I haven't tackled to contain yet as that would require me to add that to unexpected-dom (would make sense). Just so you don't get confused about that input not changing.

@sunesimonsen
Copy link
Collaborator Author

@Anifacted made me aware that the shallow rendered is useful for unit tests. So we should probably keep that around and use htmllike for it.

@sunesimonsen
Copy link
Collaborator Author

It is also an interesting fact that snapshot testing in Jest renders the native elements.

@sunesimonsen
Copy link
Collaborator Author

sunesimonsen commented Mar 15, 2018

I find it an intriguing thought that you might be able to test your React components by only looking at the rendered DOM. What would you need, a very thin wrapper around React TestUtils to mount and return the DOM node, use node.querySelector('...') to find stuff. Simulate events using TestUtils. I'm just thinking out the box, don't worry.

@sunesimonsen
Copy link
Collaborator Author

I tried out the idea, it is pretty interesting. With out any fancyness you can achieve the following with test utils and unexpected-dom:

    describe("when clicking on the close button", () => {
      it("closes the sidebar", async () => {
        const rendered = findDOMNode(
          renderIntoDocument(
            <Provider store={store}>
              <WorkflowSidebar articleId={String(articles[0].id)} />
            </Provider>
          )
        );

        Simulate.click(
          rendered.querySelector('[data-test-id="showArticleSettings"]')
        );

        Simulate.click(
          rendered.querySelector('[data-test-id="closeArticleSettings"]')
        );

        expect(
          rendered,
          "to contain no elements matching",
          '[data-test-id="editSidebar"]'
        );
      });

fast

@sunesimonsen
Copy link
Collaborator Author

I by the way found a pretty significant problem with to satisfy in unexpected-dom where is requires you to state all children on the left hand side. That would need to change if we want to more in this direction.

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.

None yet

1 participant