Repository: angular/angular
File: packages/core/testing/src/test_bed.ts (TypeScript)

Code before:
  overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;

  overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;

  overrideTemplate(component: Type<any>, template: string): TestBed;

  /**
   * Overwrites all providers for the given token with the given provider definition.
   */
  overrideProvider(
    token: any,
    provider: {useFactory: Function; deps: any[]; multi?: boolean},
  ): TestBed;
  overrideProvider(token: any, provider: {useValue: any; multi?: boolean}): TestBed;
  overrideProvider(
    token: any,
    provider: {useFactory?: Function; useValue?: any; deps?: any[]; multi?: boolean},
  ): TestBed;

  overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;

  createComponent<T>(component: Type<T>, options?: TestComponentOptions): ComponentFixture<T>;

  /**
   * Execute any pending effects.
   *
   * @deprecated use `TestBed.tick()` instead
   */
  flushEffects(): void;

  /**
   * Execute any pending work required to synchronize model to the UI.
   *
   * @publicApi 20.0
   */
  tick(): void;
}

let _nextRootElementId = 0;

/**
 * Returns a singleton of the `TestBed` class.
 *
 * @publicApi
 */
export function getTestBed(): TestBed {
  return TestBedImpl.INSTANCE;
}

/**
 * @description

Review comment (refactor):
The documentation doesn't warn about throwing if two fixtures have been created.
But I don't really understand the point of throwing in that case, TBH. It just seems to reduce the utility of this method for no advantage I can see.

I do have usecases where I do create two fixtures because one has side effects that are needed by the tested component (like storing reusable TemplateRef into a service).

Code after:
  overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;

  overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;

  overrideTemplate(component: Type<any>, template: string): TestBed;

  /**
   * Overwrites all providers for the given token with the given provider definition.
   */
  overrideProvider(
    token: any,
    provider: {useFactory: Function; deps: any[]; multi?: boolean},
  ): TestBed;
  overrideProvider(token: any, provider: {useValue: any; multi?: boolean}): TestBed;
  overrideProvider(
    token: any,
    provider: {useFactory?: Function; useValue?: any; deps?: any[]; multi?: boolean},
  ): TestBed;

  overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;

  createComponent<T>(component: Type<T>, options?: TestComponentOptions): ComponentFixture<T>;

  /**
   * Returns the most recently created `ComponentFixture`, or throws an error if one has not
   * yet been created.
   */
  getFixture<T = unknown>(): ComponentFixture<T>;

  /**
   * Execute any pending effects.
   *
   * @deprecated use `TestBed.tick()` instead
   */
  flushEffects(): void;

  /**
   * Execute any pending work required to synchronize model to the UI.
   *
   * @publicApi 20.0
   */
  tick(): void;
}

let _nextRootElementId = 0;

/**
 * Returns a singleton of the `TestBed` class.
 *
 * @publicApi
 */