dwightjack / vue-types

Vue Prop Types definitions
https://dwightjack.github.io/vue-types/
MIT License
572 stars 35 forks source link

Question: testing and covering shapes with jest #78

Open ChriBack opened 3 years ago

ChriBack commented 3 years ago

Hi,

I am new to vue-types and developing in a project with testing and code coverage with jest. My problem ist, that jest/istanbul is telling me that "function not covered" when it comes to shapes.

image In the image you can see the problem. the vue component looks like this

import VueTypes from 'vue-types';
import { contractStatus } from '@/global-js/mappings';

export default {
  name: 'BankAccountEditListContractStatus',

  props: {
    status: VueTypes.shape({
      color: VueTypes.oneOf(Object.keys(contractStatus)).isRequired,
      tooltip: VueTypes.string,
    }).def(() => ({ tooltip: '' })),
    power: VueTypes.string.isRequired,
    tooltipPrice: VueTypes.string.def(''),
  },

  computed: {
    statusClass() {
      return `is-${contractStatus[this.status.farbe].color}`;
    },
  },
}

Any thoughts on how i can cover this?

Thank you in advance

dwightjack commented 3 years ago

Hi,

sorry for the late reply. I am not that familiar with jest code coverage to tell why it thinks that the prop is not covered.

If it was the def arrow function, you could change it to .def({ tooltip: '' }) (vue-types makes a shallow copy internally), but I am not sure it will fix your issue.