Skip to content

Replace setProps with rerender Function #173

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
merged 1 commit into from
Nov 20, 2020

Conversation

ITenthusiasm
Copy link
Contributor

  • Removed setProps function (and tests) to confirm with Testing
    Library standards.
  • Added rerender function (and tests) to make the API more familiar to
    the Testing Library family.

@codecov
Copy link

codecov bot commented Nov 15, 2020

Codecov Report

Merging #173 (4dc3ef2) into next (9e20198) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              next      #173   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           53        58    +5     
  Branches         9         9           
=========================================
+ Hits            53        58    +5     
Impacted Files Coverage Δ
src/vue-testing-library.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e20198...4dc3ef2. Read the comment docs.

@ITenthusiasm
Copy link
Contributor Author

@afontcu Done!

@ITenthusiasm
Copy link
Contributor Author

Noticed that @testing-library/vue was being used as an alias to import from the actual JavaScript file in the repository, so I updated my code to conform to the standard.

However, in the future, I think it would be worth simply pointing to the actual file. Doing so would remove the need for the special Jest configuration. More importantly, it would create less confusion for other contributors. Taking a quick look at RTL and STL, they seem to use the regular file name as well instead of using an alias. I'm not going to address that in this PR though. Just pointing something out so it's not forgotten.

@afontcu
Copy link
Member

afontcu commented Nov 15, 2020

Noticed that @testing-library/vue was being used as an alias to import from the actual JavaScript file in the repository, so I updated my code to conform to the standard. However, in the future, I think it would be worth simply pointing to the actual file.

I did so to make it simpler for users to just "copy&paste" the examples into their codebase and get them working, but I'm totally open to suggestions :)

Copy link
Member

@afontcu afontcu left a comment

Choose a reason for hiding this comment

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

Looks good! Left some comments here and there

@@ -47,7 +47,7 @@ function render(
// additionalOptions = configurationCb(router)
// }

const wrapper = mount(
let wrapper = mount(
Copy link
Member

Choose a reason for hiding this comment

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

No need to make it mutable, right? Could we just create a local variable inside of rerender at leave this as a const?

Copy link
Contributor Author

@ITenthusiasm ITenthusiasm Nov 15, 2020

Choose a reason for hiding this comment

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

Yeah see, that's the hard part. Because the properties in the returned object point to wrapper, that binding is actually what needs to be updated. If wrapper is const, then it can't be reassigned. So when rerender is called, the original wrapper is destroyed, a new component is mounted, and the test looks fine. But any consecutive times that rerender is called in the same test (which is a realistic scenario), the code will be working with a reference to the oldest wrapper, not the new one. So nothing new will be destroyed, and the DOM will get polluted very quickly. Moreover, users will be unable to take advantage of all utility functions that use wrapper (for the aforementioned reason).

Theoretically, there might be some things we could try to keep it const? But in the interest of keeping things simple, I think it's best to use let. But as long as we're careful about how we use wrapper, we should be okay.

I promise I did try using const before my first commit, though! 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Due to what I just described, I updated the first test to call rerender twice. This should help avoid unexpected bugs, like in the case of the updateProps test on master.

Since I didn't submit a code change for this one, I'll leave the resolution up to you. If you think of any simple workarounds let me know. I'll keep thinking while the PR is open.

Comment on lines 80 to 91
wrapper = mount(
TestComponent,
merge({
attachTo: container,
global: {
plugins,
},
...mountOptions,
props,
// ...additionalOptions,
}),
)
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to create come sort of a mountComponent function (or something with a better name 😇) to avoid repeating this code block? Both rendering methods must have the same keys, and having them in a single place looks like a good thing.

Copy link
Member

Choose a reason for hiding this comment

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

Hm, it could even include the unwrap + add lines below 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

React Testing Library has something like that. At a first glance I think it should be doable.

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 added my first iteration of the function. Let me know what you think! The 2 original blocks of code were slightly different due to the overwrite of props, so I had to include that in the arrow function. But besides that, I think it's okay. If you're fine with it, you can resolve this piece. If not, you can let me know! 😄

@ITenthusiasm ITenthusiasm force-pushed the add-rerender branch 2 times, most recently from 40eab96 to 9779bcc Compare November 15, 2020 11:22
* Removed `setProps` function (and tests) to confirm with Testing
Library standards.
* Added `rerender` function (and tests) to make the API more familiar to
the Testing Library family.
@ITenthusiasm
Copy link
Contributor Author

I did so to make it simpler for users to just "copy&paste" the examples into their codebase and get them working, but I'm totally open to suggestions :)

Ah, I see. That makes sense. I'll think about it a bit more before opening up a PR. Thanks!

@ITenthusiasm
Copy link
Contributor Author

Hey! I noticed that you added some reactions to my comments that seemed positive. Since the PR hasn't been merged yet and I haven't seen any new comments, I just wanted to double check and make sure whether you wanted me to add any more changes or not.

@afontcu
Copy link
Member

afontcu commented Nov 16, 2020

Hey! I noticed that you added some reactions to my comments that seemed positive. Since the PR hasn't been merged yet and I haven't seen any new comments, I just wanted to double check and make sure whether you wanted me to add any more changes or not.

Hey! yeah, it looks good :) I'll be probably merging and releasing it soon. Thanks! 🚀

@afontcu afontcu merged commit ebe23d8 into testing-library:next Nov 20, 2020
@github-actions
Copy link

🎉 This PR is included in version 6.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

2 participants