Vue-Test-utils包装器未通过

问题描述

我正在为我的组件编写此测试:

  test('display the bar when start is called',() => {
    const wrapper = shallowMount(ProgressBar)
    expect(wrapper.classes()).toContain('hidden')
    wrapper.vm.start()
    console.log(wrapper.vm.hidden) // false
    console.log(wrapper.vm.start()) // undefined
    expect(wrapper.classes()).not.toContain('hidden')
  })

  test('sets the bar to 100% width when the finish is called',() => {
    const wrapper = shallowMount(ProgressBar)
    expect(wrapper.element.style.width).toBe('0%')
    wrapper.vm.start()
    wrapper.vm.finish()
    expect(wrapper.element.style.width).toBe('100%')
  })

在我的ProgressBar组件中,我有

<template>
  <div :class="{ hidden: hidden }" :style="{ width: `${percent}%` }"
></div>
</template>

<script>
export default {
  data () {
    return {
      hidden: true,percent: 0
    }
  },methods: {
    start () {
      this.hidden = false
    },finish () {
      this.percent = 100
      this.hidden = true
    }
  }
}
</script>

但是测试失败,因为它的静止图像显示为true,百分比显示为0,这是我做错了吗?

这里是repo

解决方法

您应该等待处理以下修改所需的下一个刻度: Private Sub CommandButton1_Click() Dim v As Integer For v = 0 To Me.ListBox2.ListCount If v = 0 Then frmForm.lstLE.Text = Me.ListBox2.List(v) 'This is where i find the error Else frmForm.lstLE.Text = frmForm.lstLE.Text & vbCrLf & Me.ListBox2.List(v) 'This is where i find the error End If Next les.Hide End Sub Private Sub ListBox1_MouseUp(ByVal Button As Integer,ByVal Shift As Integer,ByVal X As Single,ByVal Y As Single) lastrow = Sheet12.Cells(Rows.Count,1).End(xlUp).Row Me.ListBox2.Clear For selItm = LBound(Me.ListBox1.List) To UBound(Me.ListBox1.List) If Me.ListBox1.Selected(selItm) = True Then curval = Me.ListBox1.List(selItm,0) For r = 2 To lastrow Control = Sheet12.Cells(r,"b") If Sheet12.Cells(r,"a") = curval Then Me.ListBox2.AddItem Control End If Next r End If Next selItm End Sub

await wrapper.vm.$nextTick()