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

setData on writable computed property does not seem to work as it does in VTU.1 #2085

Open
nsakiya-incomm opened this issue Nov 25, 2023 · 0 comments

Comments

@nsakiya-incomm
Copy link

Subject of the issue

I'm trying to test a little logic inside the setter of a computed property by calling "wrapper.setData({ selectedValue: ["Work","Home"] }). It ran fine in VTU v.1, but it doesn't seem to call the setter at all in v.2. I'm wondering if this feature is still being supported as I don't see the computed property is mentioned in v.2 documentation at all. Or, am I missing something here.

computed: {
selectedValue: {
get() {
if (!this.multiple && this.$store.getters.selectedLocation!=null) {
return this.$store.getters.selectedLocation[0]
} else {
return this.$store.getters.selectedLocation;
}
},
set(value) {
if (this.multiple && value && value.length > 1 && value.length > this.$store.getters.selectedLocation.length) {
let sortedSelectedItems = value.sort((a,b) => {
if (a === "All Locations") {
return -1;
} else if (b === "All Locations") {
return 1;
} else {
return a.toLowerCase().localeCompare(b.toLowerCase())
}
})
value = sortedSelectedItems;
}

if (!this.multiple && value!=null) {
value = [value];
}
this.$store.commit("setSelectedLocation", value);
}
},
...
},

Here's the test.

wrapper = mount(Component, {
attachTo: "#root",
global: {
mocks: {
$http: axios
},
plugins: [store, vuetify]
}
});
wrapper.setData({ selectedValue: ["Work","Home"] });
expect(wrapper.vm.selectedValue).toMatchObject(["Home","Work"]);

Steps to reproduce

Having a component with writable computed property with a test that updates the property as shown above.

Expected behaviour

selectedValue should contain an array of ["Home","Work"] in alphabetical order.

Actual behaviour

After running the test, the selectedValue doesn't get updated, and still hold the default value.

Possible Solution

I couldn't find any workaround. No one is really mentioning about this.

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

No branches or pull requests

1 participant