feat: init and fork some code from angular-auth-oidc-client
Some checks are pending
Build, Lint & Test Lib / Built, Lint and Test Library (push) Waiting to run
Build, Lint & Test Lib / Angular latest (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular latest Standalone & Schematics Job (push) Blocked by required conditions
Build, Lint & Test Lib / Angular 16 & RxJs 6 (push) Blocked by required conditions
Build, Lint & Test Lib / Angular V16 (push) Blocked by required conditions
Docs / Build and Deploy Docs Job (push) Waiting to run
Docs / Close Pull Request Job (push) Waiting to run

This commit is contained in:
2025-01-18 01:05:00 +08:00
parent 276d9fbda8
commit 983254164b
201 changed files with 35689 additions and 0 deletions

49
test/auto-mock.ts Normal file
View File

@@ -0,0 +1,49 @@
import { Provider } from 'injection-js';
export function mockClass<T>(obj: new (...args: any[]) => T): any {
const keys = Object.getOwnPropertyNames(obj.prototype);
const allMethods = keys.filter((key) => {
try {
return typeof obj.prototype[key] === 'function';
} catch (error) {
return false;
}
});
const allProperties = keys.filter((x) => !allMethods.includes(x));
const mockedClass = class T {};
allMethods.forEach(
(method: string) =>
((mockedClass.prototype as any)[method] = (): void => {
return;
})
);
allProperties.forEach((method) => {
Object.defineProperty(mockedClass.prototype, method, {
get() {
return '';
},
configurable: true,
});
});
return mockedClass;
}
export function mockProvider<T>(obj: new (...args: any[]) => T): Provider {
return {
provide: obj,
useClass: mockClass(obj),
};
}
export function mockAbstractProvider<T, M extends T>(
type: abstract new (...args: any[]) => T,
mockType: new (...args: any[]) => M
): Provider {
const mock = mockClass(mockType);
return { provide: type, useClass: mock };
}

View File

@@ -0,0 +1,12 @@
import { Observable, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
// Create retriable observable stream to test retry / retryWhen. Credits to:
// https://stackoverflow.com/questions/51399819/how-to-create-a-mock-observable-to-test-http-rxjs-retry-retrywhen-in-angular
export const createRetriableStream = (...resp$: any): Observable<any> => {
const fetchData: jasmine.Spy = jasmine.createSpy('fetchData');
fetchData.and.returnValues(...resp$);
return of(null).pipe(switchMap((_) => fetchData()));
};