小编Chu*_*Lin的帖子

在 bootstrap-vue modal (b-modal) int 测试中找不到按钮

我想在我的测试用例中测试模态行为。

  1. 通过页面上的按钮打开模式(isVisible false=> true)
  2. 通过模态上的按钮关闭模态(isVisible trye=> false)

第一步是可以的,但是第二步就失败了。我可以通过ref找到模态,但我找不到模态上的按钮。

首页.vue

<template>
  <div class="home">
    <b-button id='button-open' @click="open">open</b-button>
    <b-modal
      ref="modal-ref"
      hide-footer
    >
      <b-button id='button-close' @click="close">close</b-button>
    </b-modal>
  </div>
</template>


<script>
export default {
  methods: {
    open() {
      console.log('open');
      this.$refs['modal-ref'].show();
    },
    close() {
      console.log('ok');
      this.$refs['modal-ref'].hide();
    },
  },
};
</script>
Run Code Online (Sandbox Code Playgroud)

home.spec.js

<template>
  <div class="home">
    <b-button id='button-open' @click="open">open</b-button>
    <b-modal
      ref="modal-ref"
      hide-footer
    >
      <b-button id='button-close' @click="close">close</b-button>
    </b-modal>
  </div>
</template>


<script>
export default {
  methods: {
    open() {
      console.log('open');
      this.$refs['modal-ref'].show();
    },
    close() {
      console.log('ok');
      this.$refs['modal-ref'].hide();
    },
  },
};
</script> …
Run Code Online (Sandbox Code Playgroud)

bootstrap-modal vue.js bootstrap-4 vue-test-utils bootstrap-vue

4
推荐指数
1
解决办法
1968
查看次数