1

I have this component:

    export default class ModalDetails extends Vue {
  mounted(): void {
    (this.$refs.modal as any).open();
  }
}

which I am trying to test:

describe('ModalDetails', () => {
  let wrapper: Wrapper<Vue>;
  let store: Store<any>;

  beforeEach(() => {
    wrapper = mount(ModalDetails, {
      localVue,
      store,
    });
}

but I am getting this error thrown: [Vue warn]: Error in mounted hook: "TypeError: this.$refs.modal.open is not a function"

can someone help?

1 Answer 1

0

The solution to this is to mock the function in the test:

      const mixinComponent = Vue.extend({
      mixins: [ModalDetails],
      methods: {
        mounted: () => {
          /* empty function */
        },
      },
});

then in the component itself:

export default class ModalDetails extends Vue {
  mounted(): void {
    this.open();
  }
  open() {
   (this.$refs.modal as any).open();
}
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.