Skip to content

Repro all regressions to fix before 2.0 #1293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/components/ParentComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div class="parent">
<div>child</div>
<div>child</div>
<div>child</div>
</div>
</template>
12 changes: 12 additions & 0 deletions tests/components/LastUpdated.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div class="last-updated" v-if="when">
Last update: <span>{{ when }}</span>
</div>
</template>

<script>
export default {
name: 'last-updated',
props: ['when']
}
</script>
7 changes: 7 additions & 0 deletions tests/components/ParentComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div class="parent">
<div>child</div>
<div>child</div>
<div>child</div>
</div>
</template>
17 changes: 17 additions & 0 deletions tests/features/suspense.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SuspenseComponent from '../components/Suspense.vue'
import { mount, flushPromises } from '../../src'
import { defineComponent } from '@vue/compat'

let mockShouldError = false
jest.mock('../utils', () => ({
Expand Down Expand Up @@ -32,4 +33,20 @@ describe('suspense', () => {

expect(wrapper.html()).toContain('Error!')
})

test('returns the element if it is a root element inside Suspense', () => {
const Async = defineComponent({
// works if there is a root element
// template: '<div><h1>Hello</h1><span id="my-span">There</span></div>'
// otherwise does not find the element
template: '<h1>Hello</h1><span id="my-span">There</span>'
})
const Component = defineComponent({
components: { Async },
template: '<Suspense><Async/></Suspense>'
})

const wrapper = mount(Component)
expect(wrapper.get('#my-span')).not.toBeNull()
})
})
10 changes: 10 additions & 0 deletions tests/find.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineComponent, h, nextTick, Fragment } from 'vue'

import { mount, VueWrapper } from '../src'
import SuspenseComponent from './components/Suspense.vue'
import ParentComponent from './compodefineComponentponent.vue'
import MultipleRootRender from './components/MultipleRootRender.vue'

describe('find', () => {
Expand Down Expand Up @@ -347,4 +348,13 @@ describe('findAll', () => {
expect(wrapper.findAll('a')).toHaveLength(3)
})
})

// https://github.com/vuejs/test-utils/issues/1233
it('finds 3 children', () => {
const wrapper = mount(ParentComponent)

const parent = wrapper.get('.parent')

expect(parent.findAll('div').length).toBe(3)
})
})
17 changes: 17 additions & 0 deletions tests/unmount.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineComponent } from 'vue'
import LastUpdated from './components/LastUpdated.vue'

import { mount } from '../src'

Expand Down Expand Up @@ -41,4 +42,20 @@ describe('Unmount', () => {
wrapper.unmount()
expect(errorHandler).not.toHaveBeenCalled()
})

it("The LastUpdated component renders the 'when' property", async () => {
const wrapper = mount(LastUpdated, { props: { when: 'today' } })

await wrapper.vm.$nextTick()
expect(wrapper.html()).toContain('<span>today</span>')
wrapper.unmount()
})

it("The LastUpdated component doesn't render when 'when' is undefined", async () => {
const wrapper = mount(LastUpdated, { props: { when: undefined } })

await wrapper.vm.$nextTick()
expect(wrapper.html()).not.toContain('<span>today</span>')
wrapper.unmount()
})
})