Skip to content

setData doesn't work #538

@human33

Description

@human33

wrapper.setData doesn't set data in component. It sets data only in wrapper.vm object.

I created a simple components:

<template>
    nothing here
</template>

<script>
export default {
    data() {
        return {
            field: null
        };
    },
    computed: {
        isFieldNull() {
            return this.field == null;
        }
    }
}
</script>

And a test:

import { shallowMount } from '@vue/test-utils'
import testSetData from '../../src/cart/testSetData';
import { nextTick } from 'vue';


describe("test set data component", () => {
    it ("should set data", async () => {
        let wrapper = shallowMount(testSetData, {
            data () {
                return {
                    field: null
                }
            }
        });

        expect(wrapper.vm.isFieldNull).toBe(true);

        await wrapper.setData({ field: 10 });
        await nextTick();


        expect(wrapper.vm.field).toEqual(10);
        expect(wrapper.vm.isFieldNull).toBe(false);
    })
})

And the test fails on expect(wrapper.vm.isFieldNull).toBe(false); because field is still null.
Am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions