-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vue): go back to correct view with memory history (#25732)
resolves #25705
- Loading branch information
1 parent
36bea1c
commit 8327889
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { mount } from '@vue/test-utils'; | ||
import { createRouter, createMemoryHistory } from '@ionic/vue-router'; | ||
import { | ||
IonContent, | ||
IonHeader, | ||
IonToolbar, | ||
IonBackButton, | ||
IonicVue, | ||
IonApp, | ||
IonRouterOutlet, | ||
IonPage, | ||
} from '@ionic/vue'; | ||
import { waitForRouter } from './utils'; | ||
|
||
const App = { | ||
components: { IonApp, IonRouterOutlet }, | ||
template: '<ion-app><ion-router-outlet /></ion-app>', | ||
} | ||
|
||
describe('createMemoryHistory', () => { | ||
beforeAll(() => { | ||
(HTMLElement.prototype as HTMLIonRouterOutletElement).commit = jest.fn(); | ||
}); | ||
it('should not error when going back with memory router', async () => { | ||
const PageTemplate = { | ||
template: ` | ||
<ion-page> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-back-button></ion-back-button> | ||
</ion-toolbar> | ||
</ion-header> | ||
<ion-content></ion-content> | ||
</ion-page> | ||
`, | ||
components: { IonPage, IonContent, IonHeader, IonToolbar, IonBackButton } | ||
} | ||
|
||
const router = createRouter({ | ||
history: createMemoryHistory(process.env.BASE_URL), | ||
routes: [ | ||
{ path: '/', component: PageTemplate }, | ||
{ path: '/page2', component: PageTemplate }, | ||
{ path: '/page3', component: PageTemplate } | ||
] | ||
}); | ||
const push = jest.spyOn(router, 'back') | ||
|
||
router.push('/'); | ||
await router.isReady(); | ||
const wrapper = mount(App, { | ||
global: { | ||
plugins: [router, IonicVue] | ||
} | ||
}); | ||
|
||
router.push('/page2'); | ||
await waitForRouter(); | ||
|
||
router.push('/page3'); | ||
await waitForRouter(); | ||
|
||
|
||
const backButtons = wrapper.findAllComponents(IonBackButton); | ||
const pageTwoButton = backButtons[1]; | ||
const pageThreeButton = backButtons[2]; | ||
|
||
await pageThreeButton.trigger('click'); | ||
await waitForRouter(); | ||
|
||
await pageTwoButton.trigger('click'); | ||
await waitForRouter(); | ||
|
||
expect(push).toHaveBeenCalledTimes(2); | ||
}); | ||
}) |