當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript test-helpers.getContext函數代碼示例

本文整理匯總了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;
}
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:7,代碼來源:get-service.ts

示例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);
}
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:8,代碼來源:refresh.ts

示例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;
};
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:10,代碼來源:text-for.ts

示例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();
}
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:12,代碼來源:clear-local-storage.ts

示例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);
    });
  }
};
開發者ID:NullVoxPopuli,項目名稱:emberclear,代碼行數:21,代碼來源:stub-service.ts


注:本文中的@ember/test-helpers.getContext函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。