2

Is there any example how to write test case in vue? The click event not working.

The template in App.vue

<template>
<div class="main">
<textarea v-model="input" id="input" rows="3" placeholder="Please entry colors, eg: '#000','#fff' or ['#000', '#fff']"></textarea>
<button type="button" class="btn btn-primary parse" @click="parse">Go!</button>
<ul>
    <li v-for="color in colors">
      <span v-bind:style="{ background: color}"></span>
      {{color}}
    <li>
</ul>

karma test

describe('App.vue', () => {
it('should render correct color', () => {
const vm = new Vue({
  template: "<div><app></app></div>",
  components: {
    App
  }
}).$mount()
console.log(vm.$el)
vm.input = '#333, #444'
vm.$el.querySelector('.btn').click()
expect(vm.$el.querySelector('ul li:eq(0) span').style.background).toBe('#333')
 })
})

And I have output the vm.$el, it shows like below, missing the v-model and @click
enter image description here

gurghet
  • 7,591
  • 4
  • 36
  • 63
Awakening
  • 3,615
  • 8
  • 35
  • 51

1 Answers1

0

Does it give you any error? Are you using PhantomJS as browser? I don't think click is supported on PhantomJS See here PhantomJS; click an element

Community
  • 1
  • 1
gurghet
  • 7,591
  • 4
  • 36
  • 63