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

Update VisualContent tests to avoid using snapshots #23

Open
lucas-varela opened this issue Oct 15, 2023 · 0 comments · May be fixed by #25
Open

Update VisualContent tests to avoid using snapshots #23

lucas-varela opened this issue Oct 15, 2023 · 0 comments · May be fixed by #25
Assignees
Labels
enhancement New feature or request

Comments

@lucas-varela
Copy link
Contributor

Description

Current VisualContent tests work, but they could be way better if they test if rendered content includes what we expect. More details below.

Requirements

  1. Update all VisualContent tests, avoiding the usage of toMatchSnapshot where possible. It's highly likely that we don't need to use snapshots in any of the tests.

Tips

Here's how these tests could work:

Image

This test will definitely break when we introduce changes to how content is rendered, so I'm not sure if it will be useful in the long term. I say we remove it.

Image

This test will most likely break, just as before, but we could test if all content was rendered instead.

This means that, instead of just checking if a snapshot won't change, you could test if the number of elements rendered inside the .sl-visual-content element matches the number of blocks in the content object.

Testing this way, even if we add new block types and update the content object, the test will keep working, as long as all blocks are correctly rendered.

Image

Instead of using a snapshot, you could select the first rendered block and check if it has exactly 40 words followed by an ellipsis (...).

Check src/VisualContent/index.tsx:97 to learn how the component truncates paragraph text, and do the same in your test.

Image

It should be pretty similar to the last test, except it should only render as many words as the excerptLength prop.

Image

This should be similar to the first test, where you asserts that the expected number of blocks are rendered.

@lucas-varela lucas-varela added the enhancement New feature or request label Oct 31, 2023
@lucas-varela lucas-varela linked a pull request Nov 6, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants