@s-libs/ng-dev
    Preparing search index...

    Class MockErrorHandler

    An error handler to be used in tests, that keeps track of all errors it handles and allows for expectations to run on them. Automatically included in AngularContext.

    it('tracks errors', () => {
    const ctx = new AngularContext();
    ctx.run(() => {
    // test something that is supposed to throw an error
    ctx.inject(ErrorHandler).handleError(new Error('special message'));

    // expect that it did
    ctx.inject(MockErrorHandler).expectOne('special message');
    });
    });

    Hierarchy

    • ErrorHandler
      • MockErrorHandler
    Index

    Constructors

    Methods

    • Expect that no errors were handled which match the given message or predicate. If a matching error was handled, fail with a message including description, if provided.

      Parameters

      • match: Match
      • Optionaldescription: string

      Returns void

    • Expect that a single error was handled that matches the given message or predicate, and return it. If no such error was handled, or more than one, fail with a message including description, if provided.

      Parameters

      • match: Match
      • Optionaldescription: string

      Returns any

    • In addition to tracking the error, this call's Angular's ErrorHandler.handleError, prints the error to the console and may print additional information that could be helpful for finding the source of the error.

      Parameters

      • error: any

      Returns void

    • Convenience method to put in a provide array, to override Angular's default error handler. You do not need to use this if you are using AngularContext, which automatically provides it.

      TestBed.configureTestingModule({
      providers: [MockErrorHandler.overrideProvider()],
      });

      Returns Provider