Skip to content

Commit

Permalink
chore: Add regression tests for vuejs#1476
Browse files Browse the repository at this point in the history
  • Loading branch information
freakzlike committed May 4, 2022
1 parent 5fa2d72 commit 0fba4d1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/components/Issue1476.vue
@@ -0,0 +1,26 @@
<template>
<div>
<template v-for="field of availableFields" :key="field.name">
<button class="field" @click="selectedField = field">
{{ field.name }}
</button>
<div
v-if="selectedField === field"
class="selectedField"
>
{{ field.name }}
</div>
</template>
</div>
</template>

<script>
export default {
props: {
availableFields: { type: Array, required: true }
},
data: () => ({
selectedField: ''
})
}
</script>
22 changes: 22 additions & 0 deletions tests/props.spec.ts
Expand Up @@ -4,6 +4,7 @@ import PropWithSymbol from './components/PropWithSymbol.vue'
import Hello from './components/Hello.vue'
import { defineComponent, h, isRef, ref } from 'vue'
import Title from './components/FunctionComponent'
import Issue1476 from './components/Issue1476.vue'

describe('props', () => {
it('returns a single prop applied to a component', () => {
Expand Down Expand Up @@ -182,6 +183,27 @@ describe('props', () => {
expect(wrapper.find('span').text()).toBe('Some value')
})

it('should keep props as same object', async () => {
// https://github.com/vuejs/test-utils/issues/1476
const wrapper = mount(Issue1476, {
props: {
availableFields: [{ name: 'Animals' }, { name: 'Cities' }]
}
})

expect(wrapper.find('.subField').exists()).toBe(false)

await wrapper.findAll('.field')[0].trigger('click')

expect(wrapper.find('.selectedField').exists()).toBe(true)
expect(wrapper.find('.selectedField').text()).toBe('Animals')

await wrapper.findAll('.field')[1].trigger('click')

expect(wrapper.find('.selectedField').exists()).toBe(true)
expect(wrapper.find('.selectedField').text()).toBe('Cities')
})

it('returns reactive props on a stubbed component shallow case', async () => {
const Foo = {
name: 'Foo',
Expand Down

0 comments on commit 0fba4d1

Please sign in to comment.