当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript faux-jax.on函数代码示例

本文整理汇总了TypeScript中faux-jax.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了on函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: setResponses

  function setResponses(response) {
    fauxJax.on('request', request => {
      if (request.requestURL === 'https://www.myapp.com/auth') {
        request.respond(
          200,
          { 'Content-Type': 'application/json' },
          JSON.stringify({
            Authorization: 'auth',
          }),
        );
        return;
      }

      if (
        request.requestURL.indexOf(
          'https://www.domain.com/_api/download/secure_url',
        ) === 0
      ) {
        setTimeout(() => {
          request.respond(
            200,
            { 'Content-Type': 'application/json' },
            JSON.stringify(response),
          );
        }, 100);
      }
    });
  }
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:28,代码来源:file-downloader.test.ts

示例2: it

  it('should download a file', async () => {
    setResponses({
      code: 0,
      message: 'OK',
      payload: {
        downloadUrl: 'download-url',
      },
    });

    fauxJax.on('request', request => {
      if (
        request.requestURL.indexOf(
          'https://www.domain.com/_api/download/secure_url',
        ) === 0
      ) {
        expect(request.requestURL).to.be.eql(
          'https://www.domain.com/_api/download/secure_url?path=%2Fimg1.jpg',
        );
      }
    });

    const downloadUrl = await fileDownloader.getDownloadUrl('/img1.jpg');

    expect(downloadUrl.downloadUrl).to.be.eql('download-url');
  });
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:25,代码来源:file-downloader.test.ts

示例3: it

    it('should upload file with default(none) lifecycle', done => {
      setResponse(fileUploadResponse);

      fauxJax.on('request', request => {
        if (
          request.requestURL.indexOf(
            'https://www.domain.com/_api/upload/url',
          ) === 0
        ) {
          expect(request.requestURL).to.equal(
            'https://www.domain.com/_api/upload/url?acl=public&mimeType=image%2Fjpeg&path=upload%2Fto%2Fthere%2Fimage.jpg',
          );
          return;
        }

        if (request.requestURL === 'https://www.domain.com/_api/upload') {
          expect(request.requestBody.get('acl')).to.eq('public');
          expect(request.requestBody.get('lifecycle')).to.eq(null);
          expect(request.requestBody.get('mimeType')).to.eq(null);
          expect(request.requestBody.get('path')).to.eql(
            'upload/to/there/image.jpg',
          );
          expect(request.requestBody.get('uploadToken')).to.eql(uploadToken);

          return;
        }
      });

      const file = new FileAPI.File('../files/image.jpg');

      (fileManager.uploadFile('upload/to/there/image.jpg', file) as UploadJob)
        .on('upload-success', () => done())
        .on('upload-error', error => done(error));
    });
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:34,代码来源:queued-file-uploader.test.ts

示例4: setResponse

 function setResponse(responseBody, responseStatus = 200) {
   fauxJax.on('request', request => {
     if (request.requestURL === 'https://www.myapp.com/auth') {
       request.respond(
         200,
         { 'Content-Type': 'application/json' },
         JSON.stringify({
           Authorization: 'auth',
         }),
       );
       return;
     }
   });
 }
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:14,代码来源:browser-http-client.test.ts

示例5: setResponse

  function setResponse(responseBody, responseStatus = 200) {
    fauxJax.on('request', request => {
      if (request.requestURL === 'https://www.myapp.com/auth') {
        request.respond(
          200,
          { 'Content-Type': 'application/json' },
          JSON.stringify({
            Authorization: 'auth',
          }),
        );
        return;
      }

      if (
        request.requestURL.indexOf('https://www.domain.com/_api/upload/url') ===
        0
      ) {
        request.respond(
          200,
          { 'Content-Type': 'application/json' },
          JSON.stringify({
            code: 0,
            message: 'OK',
            payload: {
              uploadUrl: 'https://www.domain.com/_api/upload',
              uploadToken,
            },
          }),
        );
        return;
      }

      if (request.requestURL === 'https://www.domain.com/_api/upload') {
        setTimeout(() => {
          request.respond(
            responseStatus,
            { 'Content-Type': 'application/json' },
            JSON.stringify(responseBody),
          );
        }, UPLOAD_TIMEOUT);
      }
    });
  }
开发者ID:wix,项目名称:media-platform-js-sdk,代码行数:43,代码来源:queued-file-uploader.test.ts


注:本文中的faux-jax.on函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。