File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed
Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ export default {
6565 } ) ;
6666 } ,
6767 singleSpaUnmount ( ) {
68- if ( this . parcel ) {
68+ if ( this . parcel && this . parcel . getStatus ( ) === "MOUNTED" ) {
6969 return this . parcel . unmount ( ) ;
7070 }
7171 } ,
Original file line number Diff line number Diff line change 11import { mount } from "@vue/test-utils" ;
2- import { mountRootParcel } from "single-spa" ;
2+ import {
3+ mountRootParcel ,
4+ registerApplication ,
5+ start ,
6+ triggerAppChange ,
7+ unregisterApplication ,
8+ } from "single-spa" ;
39import Parcel from "./parcel.js" ;
410
511describe ( "Parcel" , ( ) => {
612 let wrapper ;
713
14+ beforeAll ( ( ) => {
15+ start ( ) ;
16+ } ) ;
17+
818 afterEach ( ( ) => {
919 if ( wrapper ) {
1020 wrapper . destroy ( ) ;
@@ -213,6 +223,47 @@ describe("Parcel", () => {
213223 expect ( config . mounted ) . toBe ( true ) ;
214224 expect ( wrapper . find ( "button#parcel" ) . exists ( ) ) . toBe ( true ) ;
215225 } ) ;
226+
227+ it ( `doesn't throw error if parent application is unmounted` , async ( ) => {
228+ let appMounted = true ;
229+ const config = createParcelConfig ( ) ;
230+
231+ registerApplication ( {
232+ name : "parent-app-unmount" ,
233+ activeWhen ( ) {
234+ return appMounted ;
235+ } ,
236+ app : {
237+ async bootstrap ( ) { } ,
238+ async mount ( props ) {
239+ wrapper = await mount ( Parcel , {
240+ propsData : {
241+ config,
242+ mountParcel : props . mountParcel ,
243+ } ,
244+ } ) ;
245+ } ,
246+ async unmount ( ) { } ,
247+ } ,
248+ } ) ;
249+
250+ await triggerAppChange ( ) ;
251+ await tick ( ) ;
252+
253+ expect ( config . mounted ) . toBe ( true ) ;
254+
255+ appMounted = false ;
256+
257+ await triggerAppChange ( ) ;
258+
259+ expect ( config . mounted ) . toBe ( false ) ;
260+
261+ // This is what caused the error in https://github.com/single-spa/single-spa-vue/pull/95
262+ // Trying to unmount the vue component after the single-spa app already unmounted the parcel
263+ await wrapper . destroy ( ) ;
264+
265+ unregisterApplication ( "parent-app-unmount" ) ;
266+ } ) ;
216267} ) ;
217268
218269function createParcelConfig ( opts = { } ) {
You can’t perform that action at this time.
0 commit comments