本文整理匯總了TypeScript中p-event.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('redirect response contains old url', withServer, async (t, server, got) => {
server.get('/', defaultHandler);
server.get('/redirect', redirectHandler);
const {requestUrl} = await pEvent(got.stream('redirect'), 'response');
t.is(requestUrl, `${server.url}/redirect`);
});
示例2: async
test('returns streams when using stream option', withServer, async (t, server, got) => {
server.get('/stream', (_request, response) => {
response.end('ok');
});
const data = await pEvent(got('stream', {stream: true}), 'data');
t.is(data.toString(), 'ok');
});
示例3: pEvent
server.all('/abort', async (request, response) => {
emitter.emit('connection');
request.once('aborted', resolve);
response.once('finish', reject.bind(null, new Error('Request finished instead of aborting.')));
await pEvent(request, 'end');
response.end();
});
示例4: async
test('has error event', withServer, async (t, server, got) => {
server.get('/', errorHandler);
const stream = got.stream('');
await t.throwsAsync(pEvent(stream, 'response'), {
instanceOf: got.HTTPError,
message: 'Response code 404 (Not Found)'
});
});
示例5: getStream
test('`isFromCache` stream property is false after the `response` event', withServer, async (t, server, got) => {
server.get('/', cacheEndpoint);
const cache = new Map();
const stream = got.stream({cache});
const response = await pEvent(stream, 'response') as Response;
t.is(response.isFromCache, false);
t.is(stream.isFromCache, false);
await getStream(stream);
});
示例6: async
test('doesn\'t retry on streams', withServer, async (t, server, got) => {
server.get('/', () => {});
const stream = got.stream({
timeout: 1,
retry: {
retries: () => {
t.fail('Retries on streams');
}
}
});
await t.throwsAsync(pEvent(stream, 'response'));
});