本文整理汇总了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);
});
}
};