Skip to content

Commit

Permalink
Update test to make sure components are remounted when changing route…
Browse files Browse the repository at this point in the history
… components
  • Loading branch information
pleek91 committed Jan 26, 2025
1 parent 4f7ece9 commit 991e807
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/tests/routeProps.browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ import { createRoute } from '@/services/createRoute'
import { createRouter } from '@/services/createRouter'
import { defineComponent, h } from 'vue'
import { mount } from '@vue/test-utils'
import { component } from '@/utilities/testHelpers'

test('components are not remounted when props change', async () => {
const props = vi.fn().mockImplementation(() => ({ prop: 'foo' }))
const setup = vi.fn()

const route = createRoute({
name: 'test',
const routeA = createRoute({
name: 'routeA',
path: '/[param]',
component: defineComponent({
setup() {
setup()

return { props }
},
setup,
render() {
return h('div', {}, 'test')
},
}),
}, props)
})

const router = createRouter([route], {
const routeB = createRoute({
name: 'routeB',
path: '/routeB',
component,
})

const router = createRouter([routeA, routeB], {
initialUrl: '/bar',
})

Expand All @@ -50,4 +52,9 @@ test('components are not remounted when props change', async () => {
await router.route.update({ param: 'foo' })

expect(setup).toHaveBeenCalledTimes(1)

await router.push('routeB')
await router.push('routeA', { param: 'foo' })

expect(setup).toHaveBeenCalledTimes(2)
})

0 comments on commit 991e807

Please sign in to comment.