Skip to content

Fix up custom render + rerender samples #226

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

RoystonS
Copy link
Contributor

What:

This fixes the samples mentioned in issue #225.

Why:

The code samples in the README.md were incorrect.

How:

I built my own custom renderer, and once I was happy that it was working, I backported the changes to the README.md.

Checklist:

  • Documentation
  • Tests N/A
  • Ready to be merged
  • Added myself to contributors table

Note that there are a few blank lines added to the README.md, a couple of which change the formatting (e.g. around the issue links in the data-testid section). These were inserted by the repository's own pre-commit hook (presumably running prettier or some such?).

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks! Let's just see if we can improve the formatting a bit.

README.md Outdated
@@ -11,16 +11,23 @@
<hr />

[![Build Status][build-badge]][build]

Copy link
Member

Choose a reason for hiding this comment

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

Did prettier add these extra lines here? If so, could you put them all on a single line? Otherwise the badges will no longer be side-by-side and will instead take up their own lives which will not look good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Yes, I did flag exactly that up in the PR comment. I'm guessing that whoever previously modified the README.md previously skipped the prettier step. I'll go back and put them on a single line.

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'll need to remove the blank lines and add 'prettier ignore' markup. For the issue links, pre-commit/prettier automatically splits them onto separate lines, and then on a subsequent commit adds blank lines between them.

The get/query methods in the "how to override data-testid" sample
were not `.bind`ing correctly; I've replaced them with arrow functions
as suggested.  They were also passing in `container`, which wasn't
correct. Also, a `rerender` implementation is needed in such a
custom renderer, so I've added one to the sample.

I've also fixed up the separate custom rerender sample as it a)
incorrectly advertised an options parameter, and b) didn't pass
along the original baseElement.

For: testing-library#225
@RoystonS RoystonS force-pushed the pr/fix-custom-renderer-example branch from 8048df5 to d7c45f8 Compare November 27, 2018 16:38
@RoystonS
Copy link
Contributor Author

I've fought prettier and won. Revised PR with a cleaner set of changes.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thank you!

@kentcdodds kentcdodds merged commit 415616f into testing-library:master Nov 27, 2018
@kentcdodds
Copy link
Member

🎉 This PR is included in version 5.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mbest
Copy link

mbest commented Jul 25, 2020

I was searching for how to customize render and rerender and this is only example I could find. It's now no longer in the Readme.

@kentcdodds
Copy link
Member

Hi @mbest, this is what you want: https://testing-library.com/docs/react-testing-library/setup#custom-render

@mbest
Copy link

mbest commented Jul 25, 2020

Thanks for the pointer. I did get the example from here to work, but the wrapper option is a lot cleaner.

I was specifically searching for how to get rerender to work, and unfortunately, that doc page doesn't mention rerender.

@MatanBobi
Copy link
Member

MatanBobi commented Jul 26, 2020

@mbest, I think that rerender can be overriden within the response of the render function (as you can see in the doc page @kentcdodds attached).
What's the use case you're trying to solve when overriding the rerender function? Maybe if you'll explain we'll be able to show an example :)

@kentcdodds
Copy link
Member

I don't think he was trying to override the rerender method. He just wanted re-render to work nicely without having to specify any wrapping components again.

@MatanBobi
Copy link
Member

I don't think he was trying to override the rerender method. He just wanted re-render to work nicely without having to specify any wrapping components again.

Oh, my bad, didn't get that 👍 Sorry.

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

Successfully merging this pull request may close these issues.

5 participants