1

For example, how to trigger a change event in v-autocomplete inside your component, so that I

I tried something like:

import SomethingAutocomplete from "@/components/SomethingAutocomplete.vue";
import { shallowMount } from "@vue/test-utils";
import { VAutocomplete } from "vuetify/lib";
import { Constructor } from "vue/types/options";

test("Some test", async () => {
  const wrapper = shallowMount(SomethingAutocomplete);
  let ac = wrapper.find(<Constructor>VAutocomplete);
  ac.trigger("input");
  await wrapper.vm.$nextTick();
  ...
  <handler was never called>
});

Any hints? TIA.

3
  • input is an event. I suppose you want to capture it inside a parent component. Did you try ac.vm.$emit("input", valueOfTheInput); instead of ac.trigger("input"); ? Commented Apr 19, 2020 at 22:42
  • Also it is written trigger("input") in your code but you write "a change event" in your explanation. What event is it exactly ? Commented Apr 19, 2020 at 22:44
  • ac.vm.$emit("change") worked! sorry for the mix up in the example i wrote on the post. Thank you! Commented Apr 20, 2020 at 7:29

1 Answer 1

1

trigger() is only used to trigger event inside the component. Since here we want to check the behaviour on an event emitted by a child, we need to emit the event to the parent component. So this will do the job :

ac.vm.$emit("input", valueOfTheInput);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.