本文整理匯總了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' });
});
示例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);
});
示例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);
}));
});