0

How to test nested promise method written in vue component written in method

as you can see here that cancel method is nested promise so how to write test case using vue test utils & jest

<template>
  <b-button variant="danger" @click="cancel">Cancel</b-button>
</template>

<script>
export default {
  props: {
    id: {
      type: String,
      default: ''
    }
  },
  methods: {
    cancel() {
      this.$store
        .dispatch('cancel')
        .then(() => {
          this.$store
            .dispatch('getdata')
            .then(() => {})
            .catch(() => {});
          this.$emit('closeModel');
        })
        .catch(() => {});
    }
  }
};
</script>
skyboyer
  • 22,209
  • 7
  • 57
  • 64
Tapan Bavaliya
  • 135
  • 2
  • 12
  • Are you using flush-promises? https://vue-test-utils.vuejs.org/guides/testing-async-components.html – chrismarx Jan 24 '19 at 15:17
  • No i am not using flush-promises, we can but jest coverage will not cover `.catch(() => {});` so how to sure jest coverage also fullfil – Tapan Bavaliya Jan 25 '19 at 07:52
  • I would try flush-promises first, but I agree, I've had similar problems where flush-promises can't await nested promises – chrismarx Feb 14 '19 at 19:45

0 Answers0