Description
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.