Skip to content

Conversation

lmiller1990
Copy link
Member

Still not a big fan of this feature, but at least it was easy to implement 👍

setData(data: Record<string, any>) {
// lodash.merge merges by *reference* so this will update
// any existing data with the newly passed data.
merge(this.componentVM.$data, data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we guard against setting data that is not in $data already? Not sure

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's check how Vue 3 behaves. I wonder if the new reactivity API allows you to update with new properties? I think we should match whatever Vue 3 does.

@lmiller1990
Copy link
Member Author

Should I re-base and merge this? I forgot why we left this open.

@afontcu
Copy link
Member

afontcu commented Apr 22, 2020

Should I re-base and merge this? I forgot why we left this open.

I think we said to wait until later alphas, and see if people asked about this particular feature. I won't be using it personally, but some concerns were raised in the RFC so we might just add it and keep it as a low priority feature.

andyghiuta added a commit to myENA/advanced-select that referenced this pull request May 17, 2020
A test that uses `setData` is skipped. `setData` is not yet implemented
See: vuejs/test-utils/pull/52
@lmiller1990
Copy link
Member Author

lmiller1990 commented May 22, 2020

Dropped lodash dep, will need to write our own merge function before merging this. All good, no rush on this feature anyway.

@lmiller1990
Copy link
Member Author

I will close this for now, we can implement if/when we need it.

@lmiller1990 lmiller1990 closed this Aug 1, 2020
@jacobmllr95
Copy link

We at BootstrapVue are using wrapper.setData() quite heavily.
We are currently in the process of creating a Vue 3 compatible version and it would be good to have that feature in VTU v2.

I'am also willing to test this with our current tests and give feedback.

@JessicaSachs
Copy link
Contributor

JessicaSachs commented Oct 22, 2020 via email

@jacobmllr95
Copy link

You are right, we don't use it that much.
A PR would be really appreciated :)

@lmiller1990
Copy link
Member Author

lmiller1990 commented Oct 22, 2020

I think we do need to implement this - backwards compat is pretty important, we learned this from some of the aggressive deprecations in 1.0.

I think this feature is very easy to implement. I also expect a lot of push-back if we were to deprecate this. I would recommend implementing it and referencing it in the API reference part of the docs, but not including it in any of our guides (I think we settled on this been unideal in most cases - just use the data mounting option).

What does everyone think?

@jacobmllr95
Copy link

@lmiller1990 I would prefer to have this in v2 too.

A guide in the docs on why you should avoid using it and what better alternatives are seems to be a good idea.

@lmiller1990
Copy link
Member Author

The reason it's not ideal is because arbitrarily setting data on a component is not something a user can do - ideally, test like a user does. Eg, if the data is set via a button, click the button with trigger etc.

Either way, we should support this. I will make a PR in the near future unless someone else does first - you can reference this PR to see how it can be implemented.

@lmiller1990 lmiller1990 mentioned this pull request Oct 22, 2020
@JessicaSachs
Copy link
Contributor

JessicaSachs commented Oct 23, 2020 via email

@lmiller1990
Copy link
Member Author

lmiller1990 commented Oct 23, 2020

In terms of implementation, this was working https://github.com/vuejs/vue-test-utils-next/pull/52/files (this PR). Unless I am missing some specific use case.

Don't get me wrong, I still think setData sucks and is an anti-pattern in most (all?) cases ... but my opinion conflicts with "unopinionated utilities for testing" and we should put the library/community first. We can be opinionated in the docs and explain why you might not need setData 👍 and we can be opinionated in tools on top of Test Utils, like Cypress, testing-library etc.

I also think after 1.0 which was met with some criticism (many deprecations) we should learn from that experience and avoid breaking changes/surprises, if at all possible. If there is a technical limitation, that's fine, but if not let's do it.

@afontcu
Copy link
Member

afontcu commented Oct 23, 2020

I'm also OK with adding setData for the sake of avoiding breaking changes, and document it as one of the "Advanced topics" (re vuejs/test-utils-docs#17 (comment)) VTU-next offers 👍

@cexbrayat cexbrayat deleted the feature/set-data branch April 6, 2022 13:19
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.

5 participants