我收到了开玩笑测试的错误消息,无法在空包装器上调用trigger(),我不确定为什么找不到我的deleteEl
emit onDelete event to the parent
[vue-test-utils]: find did not return [data-test="deleteEl"], cannot call trigger() on empty Wrapper
47 | const chipEl = new ComponentWrapper(wrapper.findAllComponents(FilterChip).at(0))
48 | const deleteEl = chipEl.findByDataTest('deleteEl')
> 49 | deleteEl.trigger('click')
| ^
50 | expect(wrapper.emitted('deleteEl')).toBeTruthy()
51 |
52 | expect(wrapper.findAllComponents(FilterChip).length).toBe(sampleChips.length)
这是我的父组件的零件代码
<label v-for="chip of chips" :key="chip.label">
<FilterChip
:data-test="deleteEl"
:text="chip"
:key="chip.label"
v-bind="$attrs"
category="secondary"
@remove-filter-chip="deleteChip(chip)"
></FilterChip>
</label>
这是子组件
<div class="filter-chip" :title="text" :data-test="deleteEl">
<Chip :category="category" :truncated="truncated">
<span>{{ text }}</span>
<button type="button" class="btn--close" :data-test="deleteEl" @click="removeFilterChip">
<i class="material-icons">close</i>
</button>
</Chip>