Search code examples
vue.jsunit-testingjestjsvue-test-utilsvue-treeselect

How to write unit test for vue-treeselect using vue test utils


I want to write unit test on vue-treeselect. I followed the testcases written in the repository. There they have taken wrapper.vm.forest.nodemap to find the options but when i try it is giving forest "undefined".

Does anyone have idea how to get wrapper.vm.forest in the wrapper.


Solution

  • I have used treeselect something like this

    <treeselect
              v-model="selected"
              data-test="treeselect"
              :multiple="true"
              :options="options"
              placeholder
              value-consists-of="LEAF_PRIORITY"
              :required="true"
              :show-count="true"
              :default-expand-level="1"
            >
    

    I gave data-test="treeselect" to find this component than in testcase used like this:

    expect(wrapper.find('[data-test="tenants"]').vm.forest.selectedNodeIds).toEqual(["anything"]);