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


TypeScript task.toPromise函數代碼示例

本文整理匯總了TypeScript中@jonggrang/task.toPromise函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript toPromise函數的具體用法?TypeScript toPromise怎麽用?TypeScript toPromise使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了toPromise函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it('#ifRequest only apply middleware if satisfy predicate', async function () {
    const middleware = W.modifyResponse(response => W.mapResponseHeaders(response, addVaryHeaders));
    function whenPathLogin(ctx: W.HttpContext): boolean {
      return ctx.request.url === '/login';
    }
    const simpleApp: W.Application = (ctx, send) =>
      send(W.responseUtf8(200, { 'Content-Type': 'text/plain' }, 'text body'));
    const app = W.ifRequest(whenPathLogin, middleware)(simpleApp);

    // predicate hold
    const response1 = await T.toPromise(app({
      request: {
        url: '/login',
        headers: {}
      },
      state: {}
    } as any, T.pure));
    assert.deepEqual(response1.headers, {
      'Content-Type': 'text/plain',
      'Vary': 'Cookie'
    });

    // predicate not hold
    const response2 = await T.toPromise(app({
      request: {
        url: '/dashboard',
        headers: {}
      },
      state: {}
    } as any, T.pure));
    assert.deepEqual(response2.headers, { 'Content-Type': 'text/plain' });
  });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:32,代碼來源:response.test.ts

示例2: it

 it('saveSession return null if nothing to save', async function () {
   const storage = await T.toPromise(emptyMockStorage);
   const state = SS.createServerSessionState(storage);
   await T.toPromise(SS.saveSession(state, { sess: null, now: fakenow }, {}));
   const op = await getMockOperation(storage);
   assert.deepEqual(op, L.nil);
 });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:7,代碼來源:server-session.ts

示例3: it

 it('200 and etag when no etag query parameters', async () => {
   const stat = await T.toPromise(T.node(null, path.join(__dirname, 'fixture', 'attic', 'a'), fs.stat));
   const extag = await T.toPromise(defaultEtag(stat, true));
   const req = new IncomingMessageMock({ url: '/attic/a' });
   await T.toPromise(request(staticTest, req).map(resp => {
     assert.equal(resp.status, 200);
     assert.equal(resp.headers['ETag'], (extag as any).value);
   }));
 });
開發者ID:syaiful6,項目名稱:jonggrang,代碼行數:9,代碼來源:static.test.ts


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