Skip to content

Commit

Permalink
test: update standalone browser tests to not pollute test output (#46510
Browse files Browse the repository at this point in the history
)

There are a couple of tests intentionally triggering and verifying
runtime errors thrown by `bootstrapApplication`. These errors are
also printed using the default `ErrorHandler`, while also being
re-thrown and caught/asserted by the test.

The error logging should be disabled as otherwise three tests will
pollute the test output with large amounts of text that make it
also seem like actual failing tests / something incorrect going on with
the jasmine environment.

PR Close #46510
  • Loading branch information
devversion authored and dylhunn committed Jun 27, 2022
1 parent 0a84898 commit 6b8f10e
Showing 1 changed file with 18 additions and 4 deletions.
Expand Up @@ -7,7 +7,7 @@
*/

import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/common';
import {Component, destroyPlatform, Inject, Injectable, InjectionToken, NgModule} from '@angular/core';
import {Component, destroyPlatform, ErrorHandler, Inject, Injectable, InjectionToken, NgModule} from '@angular/core';
import {inject} from '@angular/core/testing';

import {bootstrapApplication, BrowserModule} from '../../src/browser';
Expand All @@ -24,6 +24,13 @@ describe('bootstrapApplication for standalone components', () => {
rootEl?.remove();
});

class SilentErrorHandler extends ErrorHandler {
override handleError() {
// the error is already re-thrown by the application ref.
// we don't want to print it, but instead catch it in tests.
}
}

it('should create injector where ambient providers shadow explicit providers', async () => {
const testToken = new InjectionToken('test token');

Expand Down Expand Up @@ -96,7 +103,12 @@ describe('bootstrapApplication for standalone components', () => {
try {
await bootstrapApplication(
StandaloneCmp,
{providers: [NeedsAmbientProvider]},
{
providers: [
{provide: ErrorHandler, useClass: SilentErrorHandler},
NeedsAmbientProvider,
]
},
);

// we expect the bootstrap process to fail since the "NeedsAmbientProvider" service
Expand All @@ -121,7 +133,8 @@ describe('bootstrapApplication for standalone components', () => {
}

try {
await bootstrapApplication(StandaloneCmp);
await bootstrapApplication(
StandaloneCmp, {providers: [{provide: ErrorHandler, useClass: SilentErrorHandler}]});

// The `bootstrapApplication` already includes the set of providers from the
// `BrowserModule`, so including the `BrowserModule` again will bring duplicate providers
Expand Down Expand Up @@ -152,7 +165,8 @@ describe('bootstrapApplication for standalone components', () => {
}

try {
await bootstrapApplication(StandaloneCmp);
await bootstrapApplication(
StandaloneCmp, {providers: [{provide: ErrorHandler, useClass: SilentErrorHandler}]});

// The `bootstrapApplication` already includes the set of providers from the
// `BrowserModule`, so including the `BrowserModule` again will bring duplicate providers
Expand Down

0 comments on commit 6b8f10e

Please sign in to comment.