Skip to content

Instantly share code, notes, and snippets.

@Toxicable
Created October 8, 2017 10:26
Show Gist options
  • Save Toxicable/b61b0742e061c5e3f2e569206c0876ac to your computer and use it in GitHub Desktop.
Save Toxicable/b61b0742e061c5e3f2e569206c0876ac to your computer and use it in GitHub Desktop.
export function validate(module: any, bootstrapComponent: any, selector = 'app-root', timeout = 5000) {
@NgModule({
imports: [
BrowserModule.withServerTransition({ appId: selector }),
module
],
declarations: [bootstrapComponent],
bootstrap: [bootstrapComponent],
})
class AppModule { }
@NgModule({
imports: [
ServerModule,
AppModule,
],
bootstrap: [bootstrapComponent],
})
class AppServerModule { }
const document = `<${selector}></${selector}>`;
let rendered = false;
setTimeout(() => {
if (!rendered) {
throw new Error('Module did not render in time. Check that all async operations have been cleaned up');
}
}, timeout);
return renderModule(AppServerModule, {
document,
}).then(html => {
rendered = true;
return html;
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment