[Vuejs]-How to unit test this vue component with jest

0👍

First you should define your functions inside the methods property. Also component scoped variables inside the data function.
Like this:

export default class Breadcrumb extends Vue {
  data() {
     return {
       breadcrumbList: []
     }
  },
  mounted(): void {
     ...
  },
  methods: {
    goTo(breadcrumb: BreadcrumbData) {
      if (breadcrumb.link) {
        this.$router.push(breadcrumb.link as RawLocation);
      }
    }
  }
}

https://v2.vuejs.org/v2/guide/instance.html#Data-and-Methods

Then you can reach them from tests too.

Leave a comment