Skip to content

Commit

Permalink
fix(app-loader): should call errorHandle when preload app assets failed
Browse files Browse the repository at this point in the history
  • Loading branch information
whyour committed Sep 18, 2019
1 parent 44357e7 commit f043018
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,59 @@ describe('PlanetApplicationLoader', () => {
expect(app2BootstrapSpy).toHaveBeenCalled();
}));

it(`should preload app`, () => {});
it(`should throw error when preload load app3 error`, fakeAsync(() => {
const newApp2 = {
...app2,
preload: true
};

planetApplicationService.unregister(app2.name);
planetApplicationService.register(newApp2);

const loadApp1Assets$ = new Subject();
const loadApp2Assets$ = new Subject();

const errorHandlerSpy = jasmine.createSpy(`error handler spy`);
planetApplicationLoader.setOptions({
errorHandler: errorHandlerSpy
});

const [app1BootstrapSpy] = spyPlanetApplicationRef(app1.name);
const [app2BootstrapSpy] = spyPlanetApplicationRef(app2.name);

const assetsLoaderSpy = spyOn(assetsLoader, 'loadAppAssets');
assetsLoaderSpy.and.returnValues(loadApp1Assets$, loadApp2Assets$);

const appStatusChangeSpy = jasmine.createSpy('app status change spy');
planetApplicationLoader.appStatusChange.subscribe(appStatusChangeSpy);

expect(appStatusChangeSpy).not.toHaveBeenCalled();
planetApplicationLoader.reroute({ url: '/app1' });
expect(appStatusChangeSpy).toHaveBeenCalled();
expect(appStatusChangeSpy).toHaveBeenCalledWith({ app: app1, status: ApplicationStatus.assetsLoading });

loadApp1Assets$.next();
loadApp1Assets$.complete();

expect(appStatusChangeSpy).toHaveBeenCalledTimes(2);
expect(appStatusChangeSpy).toHaveBeenCalledWith({ app: app1, status: ApplicationStatus.assetsLoaded });

ngZone.onStable.next();

expect(appStatusChangeSpy).toHaveBeenCalledTimes(4);
expect(appStatusChangeSpy).toHaveBeenCalledWith({ app: app1, status: ApplicationStatus.bootstrapping });
expect(appStatusChangeSpy).toHaveBeenCalledWith({ app: app1, status: ApplicationStatus.bootstrapped });

expect(app1BootstrapSpy).toHaveBeenCalled();

tick(300);
expect(app2BootstrapSpy).not.toHaveBeenCalled();

loadApp2Assets$.error(new Error(`load newApp2 assets error`));
loadApp2Assets$.complete();
expect(errorHandlerSpy).toHaveBeenCalled();
expect(errorHandlerSpy).toHaveBeenCalledWith(new Error(`load newApp2 assets error`));
}));
});

function expectApp1Element() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class PlanetApplicationLoader {
});

forkJoin(loadApps$).subscribe({
error: this.errorHandler
error: err => this.errorHandler(err)
});
});
}
Expand Down

0 comments on commit f043018

Please sign in to comment.