P
P
pkring2020-05-29 14:59:32
Unit testing
pkring, 2020-05-29 14:59:32

How to test $refs in Vue Test Utils with Jest?

The component has a method:

scrolToTop() {
      this.$refs.dialog.scrollTo(0, 0);
},


When running the test, it displays an error in the console:
TypeError: this.$refs.dialog.scrollTo is not a function

Tried to do this, but nothing happened
const wrapper = shallowMount(Component, {
      mocks: {
        $refs: {
          dialog: {
            scrollTo() {
              return true;
            }
          }
        }
      }
    });


How to work with it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question