當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript nock類代碼示例

本文整理匯總了TypeScript中nock的典型用法代碼示例。如果您正苦於以下問題:TypeScript nock類的具體用法?TypeScript nock怎麽用?TypeScript nock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了nock類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

 it('should fail if the artifact is too large', async () => {
   const artifactRequest = nock(BASE_URL).get(ARTIFACT_PATH).reply(200, ARTIFACT_CONTENTS);
   retriever = new BuildRetriever(api, 10, DOWNLOAD_DIR);
   try {
     await retriever.downloadBuildArtifact(12345, 777, 'COMMIT', ARTIFACT_PATH);
     throw new Error('Exception Expected');
   } catch (error) {
     expect(error.status).toEqual(413);
   }
   artifactRequest.done();
 });
開發者ID:BobChao87,項目名稱:angular,代碼行數:11,代碼來源:build-retriever.spec.ts

示例2: it

  it("should add required Vary headers to the response", async () => {
    nock(cloudRunApiOrigin)
      .get("/v1alpha1/projects/project-foo/locations/us-central1/services/helloworld")
      .reply(200, { status: { address: { hostname: cloudRunServiceOrigin } } });
    nock(cloudRunServiceOrigin)
      .get("/vary")
      .reply(200, "live vary version", { vary: "Other, Authorization" });

    const mwGenerator = await cloudRunProxy(fakeOptions);
    const mw = await mwGenerator(fakeRewrite);
    const spyMw = sinon.spy(mw);

    return supertest(spyMw)
      .get("/vary")
      .expect(200, "live vary version")
      .then((res) => {
        expect(spyMw.calledOnce).to.be.true;
        expect(res.header.vary).to.equal("Other, Authorization, Accept-Encoding, Cookie");
      });
  });
開發者ID:firebase,項目名稱:firebase-tools,代碼行數:20,代碼來源:cloudRunProxy.spec.ts

示例3: it

 it('should return a single response object for single requests', async () => {
   nock(Utils.baseUrl, {allowUnmocked: true})
       .post('/urlshortener/v1/url')
       .times(2)
       .replyWithFile(
           200,
           path.join(
               __dirname, '../../test/fixtures/urlshort-insert-res.json'));
   await testInsert(localUrlshortener);
   await testInsert(remoteUrlshortener);
 });
開發者ID:dmytrobanasko,項目名稱:google-api-nodejs-client,代碼行數:11,代碼來源:test.urlshortener.v1.ts

示例4: it

 it('should allow overriding validateStatus', async () => {
   const scope = nock(Utils.baseUrl).get('/drive/v2/files').reply(500);
   const google = new GoogleApis();
   const drive = google.drive('v2');
   const res = await drive.files.list({}, {
     validateStatus: (status: number) => {
       return true;
     }
   });
   assert.equal(res.status, 500);
 });
開發者ID:sgaluza,項目名稱:google-api-nodejs-client,代碼行數:11,代碼來源:test.options.ts

示例5: it

 it('should upload a video', async () => {
   const scope =
       nock(Utils.baseUrl)
           .post(
               `/upload/youtube/v3/videos?part=id%2Csnippet%2Cstatus&notifySubscribers=false&uploadType=multipart`)
           .reply(200, {kind: 'youtube#video'});
   const data = await samples.upload.runSample(someFile);
   assert(data);
   assert.strictEqual(data.kind, 'youtube#video');
   scope.done();
 });
開發者ID:perryao,項目名稱:google-api-nodejs-client,代碼行數:11,代碼來源:test.samples.youtube.ts

示例6: function

util.setupExpectedWSTrustRequestCommon = function () {
  var RSTRDoc = fs.readFileSync(parameters.RSTRFile, 'utf8');
  var wstrustRequest = nock(parameters.adfsUrlNoPath)
    .filteringRequestBody(function () { return '*'; })
    .post(parameters.adfsWsTrustPath, '*')
    .reply(200, RSTRDoc);

  util.matchStandardRequestHeaders(wstrustRequest);

  return wstrustRequest;
};
開發者ID:AzureAD,項目名稱:azure-activedirectory-library-for-nodejs,代碼行數:11,代碼來源:util.ts

示例7: it

 it('sould call callback with value', done => {
   const endpoint = 'tag/sunset';
   nock('https://api.instagram.com')
     .get(`/v1/${endpoint}`)
     .query({ access_token: 'toto' })
     .reply(200, { message: 'success' });
   (instagram as any).request('GET', endpoint, (_, result) => {
     expect(result).toMatchSnapshot();
     done();
   });
 });
開發者ID:pradel,項目名稱:node-instagram,代碼行數:11,代碼來源:index.ts

示例8: async

 async () => {
   nock(Utils.baseUrl)
       .post('/upload/drive/v2/files?uploadType=multipart')
       .times(2)
       .reply(201, (uri: string, reqBody: {}) => {
         return reqBody;  // return request body as response
                          // for testing purposes
       });
   await testMultpart(localDrive);
   await testMultpart(remoteDrive);
 });
開發者ID:perryao,項目名稱:google-api-nodejs-client,代碼行數:11,代碼來源:test.media.ts

示例9: it

    it('should set loading status as expected', function () {
      const scope = nock(BASE_URL).get('/api/settings').reply(200);
      const promise = store.load()
        .then(() => {
          scope.done();
          expect(store.loading).to.be.false;
        });

      expect(store.loading).to.be.true;
      return promise;
    });
開發者ID:Xristinaaaa,項目名稱:Telerik2016,代碼行數:11,代碼來源:SettingsStore-spec.ts


注:本文中的nock類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。