本文整理匯總了TypeScript中@ember/test-helpers.getContext函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript getContext函數的具體用法?TypeScript getContext怎麽用?TypeScript getContext使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了getContext函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getContext
export function getService<T>(name: string): T {
const { owner } = getContext();
const service = owner.lookup<T>(`service:${name}`);
return service;
}
示例2: refresh
export async function refresh(mocking: () => void = () => undefined) {
const url = currentURL();
const ctx = getContext();
await teardownContext(ctx);
await setupContext(ctx);
await mocking();
await visit(url);
}
示例3: getContext
export const textFor = (selector: string): string => {
const context = getContext();
const root = context.element;
const element = root.querySelector(selector);
const content = element && element.textContent;
const text = (content && content.trim()) || '';
return text;
};
示例4: cleanEverything
async function cleanEverything() {
const context = getContext();
if (context) {
const adapter = context.owner.lookup('adapter:application');
await adapter.cache.clear();
}
// specifically, offline storage
await localforage.clear();
await localStorage.clear();
}
示例5: getContext
export const stubService = (name: string, hash = {}, injections?: IInjection[]) => {
let stubbedService;
// TODO: need to be able to use an extended service that uses services. :)
if (hash instanceof Function) {
stubbedService = hash;
} else {
stubbedService = Service.extend(hash);
}
let { owner } = getContext();
let serviceName = `service:${name}`;
owner.register(serviceName, stubbedService);
if (injections) {
injections.forEach(injection => {
owner.application.inject(injection.in, injection.as, serviceName);
});
}
};