fix(vue): go back to correct view with memory history (#25732)

resolves #25705
This commit is contained in:
Liam DeBeasi
2022-08-08 12:28:54 -04:00
committed by GitHub
parent 36bea1ca25
commit 832788971a
2 changed files with 82 additions and 1 deletions

View File

@ -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);
});
})