SteveV
SteveV

Reputation: 441

Button Click Test Failing with Jest / VueJS

I'm trying to initiate a button click on a image, but when running the test, it keeps erroring out with find did not return cal-modal, cannot call trigger() on empty Wrapper

What am I doing wrong? Very very simplified code below:

CALENDAR.VUE

<template>
                <div class="col-xs-6 text-right">
                    <b-img ref='cal-modal' id='cal-modal' class="cal-icon" @click="displayCal" v-b-modal.date-time-modal src="/static/img/ico.png"></b-img>
                </div>

</template>

TEST FILE

import {createLocalVue, mount} from "@vue/test-utils";
import Calendar from '@/components/Calendar.vue'
import BootstrapVue from "bootstrap-vue";
const localVue = createLocalVue()
localVue.use(BootstrapVue)


  it('display cal', () => {
      const wrapper = mount(Calendar, {localVue});
      wrapper
          .find('cal-modal')
          .trigger('click')
  })

Upvotes: 4

Views: 11133

Answers (1)

Husam Elbashir
Husam Elbashir

Reputation: 7177

Try using a ref selector or an id selector. Like this ..

wrapper.find({ ref: 'cal-modal' })

Or

wrapper.find('#cal-modal')

Upvotes: 9

Related Questions