Skip to content

Commit

Permalink
Add test: Created hook in page component should not be called when la…
Browse files Browse the repository at this point in the history
…yout change
  • Loading branch information
Azurewarth0920 committed Jan 23, 2022
1 parent a45368f commit a04a21b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,38 @@ describe('RouterLayout component', () => {

expect(wrapper.html()).toMatchSnapshot()
})

it('Created hook in page component should not be called when layout changes', async (done) => {
const created = jest.fn()

const Test1 = {
layout: 'foo',
template: '<p>Test1</p>',
created,
}

const Test2 = {
layout: 'bar',
template: '<p>Test2</p>',
}

const wrapper = await mount([
{
path: '',
component: Test1,
},
{
path: 'test',
component: Test2,
},
])

wrapper.vm.$router.push('/test')

setTimeout(() => {
// Should be called only once when initiating.
expect(created).toHaveBeenCalledTimes(1)
done()
}, 200)
})
})

0 comments on commit a04a21b

Please sign in to comment.