Skip to content

docs: add marko testing library #159

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

Merged

Conversation

DylanPiercey
Copy link
Contributor

This PR adds documentation for the new @marko/testing-library and closes testing-library/dom-testing-library#290.

The above package is unreleased, but is ready to go hopefully along side this additional documentation!
Any feedback is much appreciated 😄

template, // A Marko template to render
input, // Input for the above template
options // You won't often use this, expand below for docs on options
):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
):
)

> The [cleanup](#cleanup) function should be called between tests to remove the
> created DOM nodes and keep the tests isolated.

## `render` Options
Copy link
Member

@afontcu afontcu Jun 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs looks great and solid! 👍

It's a bit weird, thou, that the "render options" section uses the same heading as the parent "render" heading. I'd suggest setting "render Options" as a third-level heading, and "container" as a fourth-level one.

Same thing with "render result" and its children.

😃

Suggested change
## `render` Options
### `render` Options

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent catches!
Updated the PR based on your comments.

Thanks for the review! 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized I missed this part:

Same thing with "render result" and its children.

I think having those as a higher heading is still useful as it causes it to show up in the side nav (and these are probably the most important parts of the lib). This is also what the react-testing-library docs have setup (

).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally right, I was thinking about that while typing, actually 🤔 Let's follow RTL example, then! If we ever feel the urge to change it we can make sure we update each framework docs :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still like moving render Options as a sub heading, since in this package there is only one option and honestly it would be very rare that people use it. Could promote it to a higher heading (as is done in the react docs) if more options become available, but I don't see that happening.

In my last commit I updated the PR to do as I said above, but I left the render Result heading alone.

I think I'm happy with it now 😄

afontcu
afontcu previously approved these changes Jun 21, 2019

### `rerender`

It'd probably be better if you test the component that's doing the prop updating
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be worded a bit more conservatively - rerender behavior is a valid thing to test for reusable components

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexkrolick I agree. This is a remnant of basing the docs off of the react ones.

Let me try to word smith this better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this section of the docs, let me know what you think 😄

---

`Marko Testing Library` is not dependent on any test runner, however it is
dependent on the test environment. These utilities work for testing both server
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dependent on the test environment. These utilities work for testing both server
dependent on browser globals. These utilities work for testing both server

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are "these utilities" in this paragraph?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe test environment is not the most clear here. Basically I am trying to express that if your tooling does not pick up on the browser field in the package.json then your tests will be running in the SSR mode. For jest this just means enabling the browser option. Just having a global JSDOM for example (as is the default for jest) will not work by itself. It's a bit of a strange thing to explain to new comers though, do you have some thoughts on how to better describe this?

these utilities really just mean the api's exposed by the package. Maybe these apis would be better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that mean you can only test built files and not individual components? AFAIK most tests that require from the src folder aren't really aware of the packaging system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can test individual components, the key is that by default the server side version of the component is resolved. For a client side version of a component to be resolved, the bundler, or test runner, needs to be aware of the browser field.

In Marko components are compiled to an optimized SSR streaming API or a VDOM api. The browser field is used to provide an appropriate runtime based on the environment.

@DylanPiercey
Copy link
Contributor Author

Let's hold on merging this for now. Going to be addressing the comments above, and I also want to have a good solution for working with events emitted from Marko components.

Will update this PR hopefully today 😄

@alexkrolick alexkrolick dismissed afontcu’s stale review June 22, 2019 00:04

pending changes

@DylanPiercey
Copy link
Contributor Author

Alright, I've improved the rerender documentation and added a section about testing emitted events from components. I think it's in a pretty good state 😄

@alexkrolick alexkrolick merged commit 4253cbe into testing-library:master Jun 22, 2019
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

Successfully merging this pull request may close these issues.

testing-library/marko
3 participants