Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

108
Visualizações
vue unit test trigger('click') not firing

I have a test in my vue project that looks like this,

it('should close on dialog close click', async () => {
    wrapper = mountWith({open :true});
    wrapper.find('.c-dialog__close').trigger('click');
    await Vue.nextTick();
    console.log(wrapper.vm.open);
    expect(wrapper.vm.open).toBe(false);
});

I am expecting wrapper.vm.open to go from true to false when the click is triggered but it's staying as false. In the actual UI the click works and show gets set to false, so there must be something in the test that wrong? The component code is below,

    <template>
    <!-- eslint-disable vue/no-v-html -->
    <div class="c-dialog" :class="{'u-block': show}" @triggerOpen="handleOpen">
        <div class="c-dialog__background" @click="handleClose">
            <div class="c-dialog__wrapper u-mt-4 u-mb-1">
                <div class="c-dialog__action u-flex">
                    <button class="c-dialog__close u-bg-denim-blue u-border-0 u-text-white" @click="handleClose()">Close</button>
                </div>
                <div class="c-dialog__main u-px-2 u-py-4 u-border u-bg-white">
                    <h4>{{ content.title }}</h4>
                    <div class="c-dialog__content u-mt-2" v-html="content.content" />
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts">

import Vue from 'vue';

export default Vue.extend({
    props: {
        content: {
            type: Object,
            required: true
        }
    },
    data() {
        return {
            show: false
        }
    },
    methods: {
        handleOpen() {
            this.show = true;
        },
        handleClose() {
            this.show = false;
        }
    }

});

</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You might have already figured it out, in your component you have 'show', but in your test you are expecting 'open' to be true.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda