build: fix build and add examples
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { HttpClientTestingBackend } from '@ngify/http/testing';
|
||||
import { InjectionToken, type Provider } from 'injection-js';
|
||||
import { InjectionToken, type Provider } from '@outposts/injection-js';
|
||||
import { HTTP_BACKEND, provideHttpClient } from 'oidc-client-rx';
|
||||
|
||||
export const HTTP_CLIENT_TEST_CONTROLLER =
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Provider } from 'injection-js';
|
||||
import type { Provider } from '@outposts/injection-js';
|
||||
|
||||
export function mockClass<T>(
|
||||
obj: new (...args: any[]) => T
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Provider } from 'injection-js';
|
||||
import type { Provider } from '@outposts/injection-js';
|
||||
import { JSDOM } from 'jsdom';
|
||||
import { AbstractRouter, type Navigation, type UrlTree } from 'oidc-client-rx';
|
||||
|
||||
@@ -8,26 +8,15 @@ export class MockRouter extends AbstractRouter {
|
||||
});
|
||||
|
||||
navigation: Navigation = {
|
||||
id: 1,
|
||||
extras: {},
|
||||
initialUrl: this.parseUrl(this.dom.window.location.href),
|
||||
extractedUrl: this.parseUrl(this.dom.window.location.href),
|
||||
trigger: 'imperative',
|
||||
previousNavigation: null,
|
||||
};
|
||||
|
||||
navigateByUrl(url: string): void {
|
||||
const prevNavigation = this.navigation;
|
||||
this.dom.reconfigure({
|
||||
url: new URL(url, this.dom.window.location.href).href,
|
||||
});
|
||||
this.navigation = {
|
||||
id: prevNavigation.id + 1,
|
||||
extras: {},
|
||||
initialUrl: prevNavigation.initialUrl,
|
||||
extractedUrl: this.parseUrl(this.dom.window.location.href),
|
||||
trigger: prevNavigation.trigger,
|
||||
previousNavigation: prevNavigation,
|
||||
};
|
||||
}
|
||||
getCurrentNavigation(): Navigation {
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
type Provider,
|
||||
ReflectiveInjector,
|
||||
type Type,
|
||||
} from 'injection-js';
|
||||
import { setCurrentInjector } from 'injection-js/lib/injector_compatibility';
|
||||
runInInjectionContext,
|
||||
} from '@outposts/injection-js';
|
||||
|
||||
export interface TestModuleMetadata {
|
||||
providers?: Provider[];
|
||||
@@ -45,9 +45,6 @@ export class TestBed {
|
||||
return newTestBed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 在 TestBed 的注入上下文中运行函数
|
||||
*/
|
||||
static runInInjectionContext<T>(fn: () => T): T {
|
||||
const injector = TestBed.#instance?.injector;
|
||||
if (!injector) {
|
||||
@@ -56,16 +53,7 @@ export class TestBed {
|
||||
);
|
||||
}
|
||||
|
||||
// 保存当前的注入器
|
||||
const previousInjector = setCurrentInjector(injector);
|
||||
|
||||
try {
|
||||
// 在注入上下文中执行函数
|
||||
return fn();
|
||||
} finally {
|
||||
// 恢复之前的注入器
|
||||
setCurrentInjector(previousInjector);
|
||||
}
|
||||
return runInInjectionContext(injector, fn);
|
||||
}
|
||||
|
||||
compileComponents(): Promise<any> {
|
||||
|
||||
Reference in New Issue
Block a user