简体   繁体   中英

Jest - test Vue.js functions declared inside reactive variables

Do you know what's the correct way to test functions that are declared inside the reactive variables in VUE . To achieve 100% coverage in the component, Jest says is needed to apply test to this functions.

Example: The function customData is inside the reactive var chartOptions and must be tested:

export default{
  name: 'component',
  data: function () {
    chartOptions: {
      customData: function ({ val1 }) {
        return val1 > 0 ? val1 * 2 : 0  
      }
        }
  }
}

I appreciate your help

Once you mount your computed in jest, you can access the function through

wrapper.vm.charOptions.customData

Then call the function as you would normally do and test its output. For branch output you probably need to call it twice

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM