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