New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@ppwcode/ng-unit-testing

Package Overview
Dependencies
Maintainers
4
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ppwcode/ng-unit-testing - npm Package Compare versions

Comparing version
20.6.1
to
21.0.0
+227
types/ppwcode-ng-unit-testing.d.ts
import { TestRequest } from '@angular/common/http/testing';
import { FileDownload } from '@ppwcode/ng-async';
import { Observable, BehaviorSubject } from 'rxjs';
import { HttpHeaders } from '@angular/common/http';
import { InjectionToken, ValueProvider } from '@angular/core';
import { Data } from '@angular/router';
declare const ERROR_MESSAGE = "Error message only used during testing.";
/**
* Function that leverages the HttpTestingController to verify that a url is called once. When the request
* is flushed, the passed `mockedResponse` value will be set as the request response value.
*
* If you want to do some checks, pass a `requestExpectations` function that will be called before flushing
* the request with the response.
* @param url The url that is expected to be called once.
* @param mockedResponse The response that should be sent when flushing the request.
* @param requestExpectations A function taking the request instance to allow verifying the request.
* @param responseOptions Optionally specify extra options for the response like status code.
*/
declare const expectOneCallToUrl: <TResponse>(url: string, mockedResponse: TResponse, requestExpectations?: (request: TestRequest) => void, responseOptions?: ResponseOptions) => void;
/**
* Verifies on the HttpTestingController that there are no outstanding requests left.
*/
declare const expectNoOutstandingRequests: () => void;
interface ResponseOptions {
headers?: HttpHeaders | {
[name: string]: string | Array<string>;
};
status?: number;
statusText?: string;
}
/**
* This class can be used in testing to leverage the HttpTestingController for HTTP call testing.
*
* @example
* it('should verify the call to /api', () => {
* const response: Array<string> = [];
*
* HttpCallTester.expectOneCallToUrl('/api')
* .whenSubscribingTo(httpClient.get('/api'))
* .checkRequest((testRequest) => { // Optional
* expect(testRequest.request.url).toEqual('/api');
* })
* .withResponse(response)
* .checkResult((result) => { // Optional
* expect(result).toBe(response);
* })
* .verify();
* });
*/
declare class HttpCallTester<TRequestResponse, TStreamResult> {
private readonly url;
/** The stream that will be subscribed to in the verify function. */
private stream$?;
/** The request response that should be returned when a request is received on the url. */
private mockedResponse?;
/** The options to further configure the response. */
private responseOptions?;
/** Verification function executed during the verify function to allow developers to set expectations on the request. */
private expectRequestFn;
/** Verification function executed during the verify function to allow developers to set expectations on the result of the stream. */
private expectStreamResultFn;
/** Verification function executed during the verify function to allow developers to set expectations on the error that is thrown. */
private expectErrorFn;
constructor(url: string);
/** Creates a new instance of HttpCallTester that can be chained to verify an HTTP call. */
static expectOneCallToUrl<TRequestResponse, TStreamResult>(url: string): HttpCallTester<TRequestResponse, TStreamResult>;
/**
* Creates a new instance of HttpCallTester that has been set up to check the retrieval of a Blob.
* It has been set up with an empty blob as the response result and expects that the stream result is the same blob.
*
* The expectation of the stream result can simply be overridden by calling `.expectStreamResultTo` again.
*
* @example
* HttpCallTester.expectOneBlobFrom('https://api/export')
* .whenSubscribingTo(httpClient.get('https://api/export))
* .verify();
* @param url The url that is expected to be called.
* @returns An HttpCallTester instance ready to verify the call.
*/
static expectOneBlobFromUrl<TStreamResult = Blob>(url: string): HttpCallTester<Blob, TStreamResult>;
/**
* Creates a new instance of HttpCallTester that has been set up to check the retrieval of a file to download.
* It has been set up with an empty blob as the response result and expects that the stream result is the same blob
* with a file name.
*
* The expectation of the stream result can simply be overridden by calling `.expectStreamResultTo` again.
*
* @example
* HttpCallTester.expectOneFileDownloadFrom('https://api/export', 'download.xlsx')
* .whenSubscribingTo(httpClient.get('https://api/export))
* .verify();
* @param url The url that is expected to be called.
* @param fileName The name of the file that is expected to be downloaded.
* @returns An HttpCallTester instance ready to verify the call.
*/
static expectOneFileDownloadFromUrl<TStreamResult = FileDownload>(url: string, fileName?: string): HttpCallTester<Blob, TStreamResult>;
/** Set the stream that will be subscribed to in the verify function. The stream should have an HTTP call as consequence. */
whenSubscribingTo(stream$: Observable<TStreamResult>): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set a function that will be executed in the verify function to check whether the request matches certain conditions. */
expectRequestTo(expectRequestFn: (request: TestRequest) => void): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set the response that will be sent by the HttpTestingController when flushing the request. */
withResponse(mockedResponse: TRequestResponse, responseOptions?: ResponseOptions): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set a function that will be executed in the verify function to check whether the stream result matches certain conditions. */
expectStreamResultTo(expectStreamResultFn: (result: TStreamResult) => void): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set a function that will be executed in the verify function to check whether the error matches certain conditions. */
expectErrorTo(expectErrorFn: (error: unknown) => void): HttpCallTester<TRequestResponse, TStreamResult>;
/**
* Verifies if an HTTP call is made successfully and triggers the verification functions that have been set.
* Also checks whether the given stream only emits once.
* Handles cleanup to prevent any memory leaks during the process.
* @throws Throws a ConditionViolation if no stream has been set.
* @throws Throws a ConditionViolation if no mocked request response has been set.
*/
verify(): void;
/**
* Verifies if an HTTP call is made unsuccessfully and triggers the verification functions that have been set.
* Also checks whether the given stream only fails once.
* Handles cleanup to prevent any memory leaks during the process.
* @throws Throws a ConditionViolation if no stream has been set.
* @throws Throws a ConditionViolation if no mocked request response has been set.
*/
verifyFailure(): void;
private verifySubscription;
}
declare const throwHttpErrorResponse: (statusCode: number) => Observable<never>;
declare const ACTIVATED_ROUTE_PARAMS: InjectionToken<BehaviorSubject<{
[key: string]: string;
}>>;
declare const ACTIVATED_ROUTE_QUERY_PARAMS: InjectionToken<BehaviorSubject<{
[key: string]: string;
}>>;
declare const ACTIVATED_ROUTE_DATA: InjectionToken<BehaviorSubject<Data>>;
/**
* Provides a mocked ActivatedRoute with dynamic BehaviorSubject instances for testing.
* Returns multiple providers including the ActivatedRoute mock and injectable BehaviorSubject instances.
* @param options Configuration object with optional route parameters, query parameters, and data
* @returns Array of ValueProvider instances for TestBed configuration
*/
declare const provideActivatedRoute: (options?: {
routeParams?: {
[key: string]: string;
};
queryParams?: {
[key: string]: string;
};
data?: Data;
}) => ValueProvider[];
/**
* Updates the route parameters during test execution.
* Merges the provided parameters with existing ones.
* @param paramsToUpdate Object containing route parameters to update
*/
declare const updateActivatedRouteParams: (paramsToUpdate: {
[key: string]: string;
}) => void;
/**
* Updates the query parameters during test execution.
* Merges the provided query parameters with existing ones.
* @param queryParamsToUpdate Object containing query parameters to update
*/
declare const updateActivatedRouteQueryParams: (queryParamsToUpdate: {
[key: string]: string;
}) => void;
/**
* Updates the route data during test execution.
* Merges the provided data with existing route data.
* @param dataToUpdate Object containing route data to update
*/
declare const updateActivatedRouteData: (dataToUpdate: Data) => void;
/**
* Asserts that the ActivatedRoute snapshot data matches the expected data.
* @param data Expected route data object
*/
declare const expectSnapshotData: (data: Data) => void;
/**
* Asserts that the ActivatedRoute snapshot parameters match the expected parameters.
* @param params Expected route parameters object
*/
declare const expectSnapshotParams: (params: {
[key: string]: string;
}) => void;
/**
* Asserts that the ActivatedRoute snapshot query parameters match the expected query parameters.
* @param queryParams Expected query parameters object
*/
declare const expectSnapshotQueryParams: (queryParams: {
[key: string]: string;
}) => void;
/**
* Asserts that the ActivatedRoute data observable emits the expected data.
* @param data Expected route data object
*/
declare const expectData: (data: Data) => Promise<void>;
/**
* Asserts that the ActivatedRoute params observable emits the expected parameters.
* @param params Expected route parameters object
*/
declare const expectParams: (params: {
[key: string]: string;
}) => Promise<void>;
/**
* Asserts that the ActivatedRoute queryParams observable emits the expected query parameters.
* @param queryParams Expected query parameters object
*/
declare const expectQueryParams: (queryParams: {
[key: string]: string;
}) => Promise<void>;
/**
* Asserts that a specific parameter in the paramMap has the expected value.
* @param propertyName Name of the parameter to check
* @param value Expected value of the parameter
*/
declare const expectParamMapValue: (propertyName: string, value: string) => Promise<void>;
/**
* Asserts that a specific parameter in the queryParamMap has the expected value.
* @param propertyName Name of the query parameter to check
* @param value Expected value of the query parameter
*/
declare const expectQueryParamMapValue: (propertyName: string, value: string) => Promise<void>;
export { ACTIVATED_ROUTE_DATA, ACTIVATED_ROUTE_PARAMS, ACTIVATED_ROUTE_QUERY_PARAMS, ERROR_MESSAGE, HttpCallTester, expectData, expectNoOutstandingRequests, expectOneCallToUrl, expectParamMapValue, expectParams, expectQueryParamMapValue, expectQueryParams, expectSnapshotData, expectSnapshotParams, expectSnapshotQueryParams, provideActivatedRoute, throwHttpErrorResponse, updateActivatedRouteData, updateActivatedRouteParams, updateActivatedRouteQueryParams };
export type { ResponseOptions };
+5
-5
{
"name": "@ppwcode/ng-unit-testing",
"version": "20.6.1",
"version": "21.0.0",
"repository": {

@@ -8,4 +8,4 @@ "url": "https://github.com/peopleware/angular-sdk"

"peerDependencies": {
"@angular/common": "^20.3.15",
"@angular/core": "^20.3.15",
"@angular/common": "^21.0.2",
"@angular/core": "^21.0.2",
"jasmine-core": "^3.9.0 || ^4.0.0 || ^5.0.0"

@@ -18,3 +18,3 @@ },

"module": "fesm2022/ppwcode-ng-unit-testing.mjs",
"typings": "index.d.ts",
"typings": "types/ppwcode-ng-unit-testing.d.ts",
"exports": {

@@ -25,3 +25,3 @@ "./package.json": {

".": {
"types": "./index.d.ts",
"types": "./types/ppwcode-ng-unit-testing.d.ts",
"default": "./fesm2022/ppwcode-ng-unit-testing.mjs"

@@ -28,0 +28,0 @@ }

import { TestRequest } from '@angular/common/http/testing';
import { FileDownload } from '@ppwcode/ng-async';
import { Observable, BehaviorSubject } from 'rxjs';
import { HttpHeaders } from '@angular/common/http';
import { InjectionToken, ValueProvider } from '@angular/core';
import { Data } from '@angular/router';
declare const ERROR_MESSAGE = "Error message only used during testing.";
/**
* Function that leverages the HttpTestingController to verify that a url is called once. When the request
* is flushed, the passed `mockedResponse` value will be set as the request response value.
*
* If you want to do some checks, pass a `requestExpectations` function that will be called before flushing
* the request with the response.
* @param url The url that is expected to be called once.
* @param mockedResponse The response that should be sent when flushing the request.
* @param requestExpectations A function taking the request instance to allow verifying the request.
* @param responseOptions Optionally specify extra options for the response like status code.
*/
declare const expectOneCallToUrl: <TResponse>(url: string, mockedResponse: TResponse, requestExpectations?: (request: TestRequest) => void, responseOptions?: ResponseOptions) => void;
/**
* Verifies on the HttpTestingController that there are no outstanding requests left.
*/
declare const expectNoOutstandingRequests: () => void;
interface ResponseOptions {
headers?: HttpHeaders | {
[name: string]: string | Array<string>;
};
status?: number;
statusText?: string;
}
/**
* This class can be used in testing to leverage the HttpTestingController for HTTP call testing.
*
* @example
* it('should verify the call to /api', () => {
* const response: Array<string> = [];
*
* HttpCallTester.expectOneCallToUrl('/api')
* .whenSubscribingTo(httpClient.get('/api'))
* .checkRequest((testRequest) => { // Optional
* expect(testRequest.request.url).toEqual('/api');
* })
* .withResponse(response)
* .checkResult((result) => { // Optional
* expect(result).toBe(response);
* })
* .verify();
* });
*/
declare class HttpCallTester<TRequestResponse, TStreamResult> {
private readonly url;
/** The stream that will be subscribed to in the verify function. */
private stream$?;
/** The request response that should be returned when a request is received on the url. */
private mockedResponse?;
/** The options to further configure the response. */
private responseOptions?;
/** Verification function executed during the verify function to allow developers to set expectations on the request. */
private expectRequestFn;
/** Verification function executed during the verify function to allow developers to set expectations on the result of the stream. */
private expectStreamResultFn;
/** Verification function executed during the verify function to allow developers to set expectations on the error that is thrown. */
private expectErrorFn;
constructor(url: string);
/** Creates a new instance of HttpCallTester that can be chained to verify an HTTP call. */
static expectOneCallToUrl<TRequestResponse, TStreamResult>(url: string): HttpCallTester<TRequestResponse, TStreamResult>;
/**
* Creates a new instance of HttpCallTester that has been set up to check the retrieval of a Blob.
* It has been set up with an empty blob as the response result and expects that the stream result is the same blob.
*
* The expectation of the stream result can simply be overridden by calling `.expectStreamResultTo` again.
*
* @example
* HttpCallTester.expectOneBlobFrom('https://api/export')
* .whenSubscribingTo(httpClient.get('https://api/export))
* .verify();
* @param url The url that is expected to be called.
* @returns An HttpCallTester instance ready to verify the call.
*/
static expectOneBlobFromUrl<TStreamResult = Blob>(url: string): HttpCallTester<Blob, TStreamResult>;
/**
* Creates a new instance of HttpCallTester that has been set up to check the retrieval of a file to download.
* It has been set up with an empty blob as the response result and expects that the stream result is the same blob
* with a file name.
*
* The expectation of the stream result can simply be overridden by calling `.expectStreamResultTo` again.
*
* @example
* HttpCallTester.expectOneFileDownloadFrom('https://api/export', 'download.xlsx')
* .whenSubscribingTo(httpClient.get('https://api/export))
* .verify();
* @param url The url that is expected to be called.
* @param fileName The name of the file that is expected to be downloaded.
* @returns An HttpCallTester instance ready to verify the call.
*/
static expectOneFileDownloadFromUrl<TStreamResult = FileDownload>(url: string, fileName?: string): HttpCallTester<Blob, TStreamResult>;
/** Set the stream that will be subscribed to in the verify function. The stream should have an HTTP call as consequence. */
whenSubscribingTo(stream$: Observable<TStreamResult>): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set a function that will be executed in the verify function to check whether the request matches certain conditions. */
expectRequestTo(expectRequestFn: (request: TestRequest) => void): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set the response that will be sent by the HttpTestingController when flushing the request. */
withResponse(mockedResponse: TRequestResponse, responseOptions?: ResponseOptions): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set a function that will be executed in the verify function to check whether the stream result matches certain conditions. */
expectStreamResultTo(expectStreamResultFn: (result: TStreamResult) => void): HttpCallTester<TRequestResponse, TStreamResult>;
/** Set a function that will be executed in the verify function to check whether the error matches certain conditions. */
expectErrorTo(expectErrorFn: (error: unknown) => void): HttpCallTester<TRequestResponse, TStreamResult>;
/**
* Verifies if an HTTP call is made successfully and triggers the verification functions that have been set.
* Also checks whether the given stream only emits once.
* Handles cleanup to prevent any memory leaks during the process.
* @throws Throws a ConditionViolation if no stream has been set.
* @throws Throws a ConditionViolation if no mocked request response has been set.
*/
verify(): void;
/**
* Verifies if an HTTP call is made unsuccessfully and triggers the verification functions that have been set.
* Also checks whether the given stream only fails once.
* Handles cleanup to prevent any memory leaks during the process.
* @throws Throws a ConditionViolation if no stream has been set.
* @throws Throws a ConditionViolation if no mocked request response has been set.
*/
verifyFailure(): void;
private verifySubscription;
}
declare const throwHttpErrorResponse: (statusCode: number) => Observable<never>;
declare const ACTIVATED_ROUTE_PARAMS: InjectionToken<BehaviorSubject<{
[key: string]: string;
}>>;
declare const ACTIVATED_ROUTE_QUERY_PARAMS: InjectionToken<BehaviorSubject<{
[key: string]: string;
}>>;
declare const ACTIVATED_ROUTE_DATA: InjectionToken<BehaviorSubject<Data>>;
/**
* Provides a mocked ActivatedRoute with dynamic BehaviorSubject instances for testing.
* Returns multiple providers including the ActivatedRoute mock and injectable BehaviorSubject instances.
* @param options Configuration object with optional route parameters, query parameters, and data
* @returns Array of ValueProvider instances for TestBed configuration
*/
declare const provideActivatedRoute: (options?: {
routeParams?: {
[key: string]: string;
};
queryParams?: {
[key: string]: string;
};
data?: Data;
}) => ValueProvider[];
/**
* Updates the route parameters during test execution.
* Merges the provided parameters with existing ones.
* @param paramsToUpdate Object containing route parameters to update
*/
declare const updateActivatedRouteParams: (paramsToUpdate: {
[key: string]: string;
}) => void;
/**
* Updates the query parameters during test execution.
* Merges the provided query parameters with existing ones.
* @param queryParamsToUpdate Object containing query parameters to update
*/
declare const updateActivatedRouteQueryParams: (queryParamsToUpdate: {
[key: string]: string;
}) => void;
/**
* Updates the route data during test execution.
* Merges the provided data with existing route data.
* @param dataToUpdate Object containing route data to update
*/
declare const updateActivatedRouteData: (dataToUpdate: Data) => void;
/**
* Asserts that the ActivatedRoute snapshot data matches the expected data.
* @param data Expected route data object
*/
declare const expectSnapshotData: (data: Data) => void;
/**
* Asserts that the ActivatedRoute snapshot parameters match the expected parameters.
* @param params Expected route parameters object
*/
declare const expectSnapshotParams: (params: {
[key: string]: string;
}) => void;
/**
* Asserts that the ActivatedRoute snapshot query parameters match the expected query parameters.
* @param queryParams Expected query parameters object
*/
declare const expectSnapshotQueryParams: (queryParams: {
[key: string]: string;
}) => void;
/**
* Asserts that the ActivatedRoute data observable emits the expected data.
* @param data Expected route data object
*/
declare const expectData: (data: Data) => Promise<void>;
/**
* Asserts that the ActivatedRoute params observable emits the expected parameters.
* @param params Expected route parameters object
*/
declare const expectParams: (params: {
[key: string]: string;
}) => Promise<void>;
/**
* Asserts that the ActivatedRoute queryParams observable emits the expected query parameters.
* @param queryParams Expected query parameters object
*/
declare const expectQueryParams: (queryParams: {
[key: string]: string;
}) => Promise<void>;
/**
* Asserts that a specific parameter in the paramMap has the expected value.
* @param propertyName Name of the parameter to check
* @param value Expected value of the parameter
*/
declare const expectParamMapValue: (propertyName: string, value: string) => Promise<void>;
/**
* Asserts that a specific parameter in the queryParamMap has the expected value.
* @param propertyName Name of the query parameter to check
* @param value Expected value of the query parameter
*/
declare const expectQueryParamMapValue: (propertyName: string, value: string) => Promise<void>;
export { ACTIVATED_ROUTE_DATA, ACTIVATED_ROUTE_PARAMS, ACTIVATED_ROUTE_QUERY_PARAMS, ERROR_MESSAGE, HttpCallTester, expectData, expectNoOutstandingRequests, expectOneCallToUrl, expectParamMapValue, expectParams, expectQueryParamMapValue, expectQueryParams, expectSnapshotData, expectSnapshotParams, expectSnapshotQueryParams, provideActivatedRoute, throwHttpErrorResponse, updateActivatedRouteData, updateActivatedRouteParams, updateActivatedRouteQueryParams };
export type { ResponseOptions };