本文整理匯總了TypeScript中nock.enableNetConnect函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript enableNetConnect函數的具體用法?TypeScript enableNetConnect怎麽用?TypeScript enableNetConnect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了enableNetConnect函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should allow default params to be overriden per-request', async () => {
const google = new GoogleApis();
const datastore =
google.datastore({version: 'v1', params: {myParam: '123'}});
// Override the default datasetId param for this particular API call
createNock('myParam=456');
const res = await datastore.projects.lookup(
// tslint:disable-next-line no-any
{projectId: 'test-project-id', myParam: '456'} as any);
// If the default param handling is broken, query might be undefined, thus
// concealing the assertion message with some generic "cannot call .indexOf
// of undefined"
const query = Utils.getQs(res) || '';
assert.notEqual(
query.indexOf('myParam=456'), -1, 'Default param not found in query');
nock.enableNetConnect();
const datastore2 = await Utils.loadApi(
google, 'datastore', 'v1', {params: {myParam: '123'}});
nock.disableNetConnect();
// Override the default datasetId param for this particular API call
createNock('myParam=456');
// tslint:disable-next-line no-any
const res2 = await (datastore2 as any).projects.lookup({
projectId: 'test-project-id',
myParam: '456'
});
// If the default param handling is broken, query might be undefined,
// thus concealing the assertion message with some generic "cannot
// call .indexOf of undefined"
const query2 = Utils.getQs(res2) || '';
assert.notEqual(
query2.indexOf('myParam=456'), -1, 'Default param not found in query');
});
示例2: before
before(async () => {
nock.cleanAll();
const google = new GoogleApis();
nock.enableNetConnect();
remoteDrive = await Utils.loadApi(google, 'drive', 'v2');
nock.disableNetConnect();
});
示例3: before
before(async () => {
nock.cleanAll();
const google = new GoogleApis();
nock.enableNetConnect();
remoteUrlshortener = await Utils.loadApi<urlshortener_v1.Urlshortener>(
google, 'urlshortener', 'v1');
nock.disableNetConnect();
});
示例4: test
test('create-from-url-network-error', function (done) {
nock.enableNetConnect();
adal.createAuthenticationParametersFromUrl('https://0.0.0.0/test', function (err) {
assert(err, 'Did not receive expected error');
nock.disableNetConnect();
done();
});
});
開發者ID:AzureAD,項目名稱:azure-activedirectory-library-for-nodejs,代碼行數:8,代碼來源:authentication-parameters.ts
示例5: before
before(async () => {
nock.cleanAll();
const google = new GoogleApis();
nock.enableNetConnect();
[remotePlus, remoteOauth2] = await Promise.all([
Utils.loadApi(google, 'plus', 'v1'), Utils.loadApi(google, 'oauth2', 'v2')
]);
nock.disableNetConnect();
});
示例6: before
before(async () => {
nock.cleanAll();
const google = new GoogleApis();
nock.enableNetConnect();
[remoteDrive, remoteGmail] = await Promise.all([
Utils.loadApi(google, 'drive', 'v2'), Utils.loadApi(google, 'gmail', 'v1')
]);
nock.disableNetConnect();
});
示例7: before
before(async () => {
nock.cleanAll();
const google = new GoogleApis();
nock.enableNetConnect();
[remoteDrive, remoteOauth2, remoteUrlshortener] = await Promise.all([
Utils.loadApi(google, 'drive', 'v2'),
Utils.loadApi(google, 'oauth2', 'v2'),
Utils.loadApi(google, 'urlshortener', 'v1'),
]);
nock.disableNetConnect();
});
示例8: test
test('failed-http-request', function (done) {
this.timeout(6000);
this.slow(4000); // This test takes longer than I would like to fail. It probably needs a better way of producing this error.
nock.enableNetConnect();
var context = new AuthenticationContext('https://0.1.1.1:12/my.tenant.com');
context.acquireTokenWithAuthorizationCode(authorizationCode, redirectUri, cp.resource, cp.clientId, cp.clientSecret, function (err) {
assert(err, 'Did not receive expected error on failed http request.');
nock.disableNetConnect();
done();
});
});
示例9: test
test('failed-http-request', function (done) {
this.timeout(6000);
this.slow(4000);
nock.enableNetConnect();
var context = new AuthenticationContext('https://0.0.0.0:11/my.test.tenant.com');
context.acquireUserCode(cp.resource, cp.clientId, cp.language, function (err) {
assert(err, 'Did not recieve expected error on failed http request.');
nock.disableNetConnect();
done();
});
});
示例10: it
it('should include default params when only callback is provided to API call', async () => {
const google = new GoogleApis();
const datastore = google.datastore({
version: 'v1',
params: {
// We must set this here - it is a required param
projectId: 'test-project-id',
myParam: '123',
},
});
// No params given - only callback
createNock('myParam=123');
const res = await datastore.projects.lookup();
// If the default param handling is broken, req or query might be
// undefined, thus concealing the assertion message with some generic
// "cannot call .indexOf of undefined"
const query = Utils.getQs(res) || '';
assert.notStrictEqual(
query.indexOf('myParam=123'),
-1,
'Default param not found in query'
);
nock.enableNetConnect();
const datastore2 = await Utils.loadApi(google, 'datastore', 'v1', {
params: {
projectId: 'test-project-id', // We must set this here - it is a
// required param
myParam: '123',
},
});
nock.disableNetConnect();
// No params given - only callback
createNock('myParam=123');
// tslint:disable-next-line no-any
const res3 = await (datastore2 as any).projects.lookup();
// If the default param handling is broken, req or query might be
// undefined, thus concealing the assertion message with some
// generic "cannot call .indexOf of undefined"
const query2 = Utils.getQs(res3) || '';
assert.notStrictEqual(
query2.indexOf('myParam=123'),
-1,
'Default param not found in query'
);
});