Skip to content

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

Open
@nsakiya-incomm

Description

@nsakiya-incomm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions