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