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


TypeScript xhr-mock.get函數代碼示例

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


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

示例1: it

  it('should error', async () => {
    mock.get('/', () => Promise.reject(new Error('😬')));

    try {
      const res = await superagent.get('/');
      expect.fail();
    } catch (error) {
      expect(error).to.be.an('Error');
      expect(error.message.toLowerCase()).to.contain('terminated');
    }
  });
開發者ID:jameslnewell,項目名稱:xhr-mock,代碼行數:11,代碼來源:superagent.test.ts

示例2: it

  it('should error', async () => {
    mock.get('/', () => Promise.reject(new Error('😬')));

    await $.ajax('/').then(
      () => expect.fail(),
      (xhr, status, error) => {
        expect(status).to.eq('error');
        expect(error).to.contain('');
      }
    );
  });
開發者ID:jameslnewell,項目名稱:xhr-mock,代碼行數:11,代碼來源:jquery.test.ts

示例3: it

  it('should time out', async () => {
    mock.get('/', () => new Promise(() => {}));

    try {
      const res = await axios.get('/', {timeout: 10});
      expect.fail();
    } catch (error) {
      expect(error).to.be.an('Error');
      expect(error.message.toLowerCase()).to.contain('timeout');
    }
  });
開發者ID:jameslnewell,項目名稱:xhr-mock,代碼行數:11,代碼來源:axios.test.ts

示例4: it

  it('should send a response containing an array buffer', done => {
    mock.get('/myfile.png', {
      body: new ArrayBuffer(0)
    });

    // sourced from https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data
    const req = new XMLHttpRequest();
    req.open('GET', '/myfile.png');
    req.responseType = 'arraybuffer';
    req.onload = () => {
      const arrayBuffer = req.response;
      expect(arrayBuffer).to.be.an('ArrayBuffer');
      done();
    };
    req.send(null);
  });
開發者ID:jameslnewell,項目名稱:xhr-mock,代碼行數:16,代碼來源:native.test.ts

示例5: resetSpies

  testNodeBase,
  conflictNode1,
  conflictNode2,
  conflictComponent1,
  conflictComponent2
} from "../Node/GomlParserTest_Registering";
import GomlLoader from "../../src/Node/GomlLoader";
import GrimoireInterface from "../../src/Interface/GrimoireInterface";
import fs from "../fileHelper";

const testcase1_goml = fs.readFile("../_TestResource/GomlNodeTest_Case1.goml");
const testcase1_html = fs.readFile("../_TestResource/GomlNodeTest_Case1.html");

xhrmock.setup();
xhrmock.get("./GomlNodeTest_Case1.goml", (req, res) => {
  return res.status(200).body(testcase1_goml);
});

let stringConverterSpy,
  testComponent1Spy,
  testComponent2Spy,
  testComponent3Spy,
  testComponentBaseSpy,
  testComponentOptionalSpy,
  conflictComponent1Spy,
  conflictComponent2Spy;

function resetSpies() {
  stringConverterSpy.reset();
  testComponent1Spy.reset();
  testComponent2Spy.reset();
開發者ID:emadurandal,項目名稱:GrimoireJS,代碼行數:31,代碼來源:NodeInterfaceTest.ts

示例6: mockXMLParse

declare namespace global {
  let Node: any;
  let document: any;
}

const testcase1_html = fs.readFile("../_TestResource/GomlLoaderTest_Case1.html");
const testcase2_html = fs.readFile("../_TestResource/GomlLoaderTest_Case2.html");
const testcase3_html = fs.readFile("../_TestResource/GomlLoaderTest_Case3.html");
const testcase4_html = fs.readFile("../_TestResource/GomlLoaderTest_Case4.html");



xhrmock.setup();
xhrmock.get("http://grimoire.gl/index.goml", (req, res) => {
  return res.status(200).body("<goml>\n</goml>");
});
xhrmock.get("http://grimoire.gl/index2.goml", (req, res) => {
  return res.status(200).body("<goml>\n</goml>");
});
xhrmock.get("http://grimoire.gl/index3.goml", (req, res) => {
  return res.status(200).body("<goml>\n</goml>");
});

function mockXMLParse(func) {
  return prequire("../../src/Node/GomlLoader", {
    "../Base/XMLReader": {
      default: {
        parseXML: (srcHtml) => {
          func(srcHtml);
          return XMLReader.parseXML(srcHtml);
開發者ID:emadurandal,項目名稱:GrimoireJS,代碼行數:30,代碼來源:GomlLoaderTest.ts

示例7: mock

 public static mock(path: string, content: string): void {
   xhrmock.get(path, (req, res) => {
     let aa = res.status(200).body(content);
     return aa;
   });
 }
開發者ID:emadurandal,項目名稱:GrimoireJS,代碼行數:6,代碼來源:PageLoadingHelper.ts


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