Class SlTestRequest<Body>

A class very similar to Angular's TestRequest for use with an AngularContext. If you are using an AngularContext, this will trigger change detection automatically after you flush a response, like production behavior.

Though it is possible to construct yourself, normally an instance of this class is obtained from ().

const ctx = new AngularContext({ providers: [provideHttpClient()] });
ctx.run(() => {
inject(HttpClient)
.get('http://example.com', { params: { key: 'value' } })
.subscribe();
const request = expectRequest<string>('GET', 'http://example.com', {
params: { key: 'value' },
});
request.flush('my response body');
});

Type Parameters

  • Body extends HttpBody

Constructors

Properties

Methods

Constructors

Properties

request: HttpRequest<any> = ...

The underlying TestRequest object from Angular.

Methods

  • Resolve the request with the given body and options, like TestRequest.flush().

    Parameters

    • body: Body
    • Optional opts: {
          headers?: HttpHeaders | {
              [name: string]: string | string[];
          };
          status?: number;
          statusText?: string;
      }
      • Optional headers?: HttpHeaders | {
            [name: string]: string | string[];
        }
      • Optional status?: number
      • Optional statusText?: string

    Returns void

  • Convenience method to flush an error response.

    Parameters

    • status: number = 500
    • __namedParameters: {
          body?: null | string | number | boolean | Object | ArrayBuffer | Blob | (null | string | number | boolean | Object)[];
          statusText?: string;
      } = {}
      • Optional body?: null | string | number | boolean | Object | ArrayBuffer | Blob | (null | string | number | boolean | Object)[]
      • Optional statusText?: string

    Returns void