本文整理汇总了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');
}
});
示例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('');
}
);
});
示例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');
}
});
示例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);
});
示例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();
示例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);
示例7: mock
public static mock(path: string, content: string): void {
xhrmock.get(path, (req, res) => {
let aa = res.status(200).body(content);
return aa;
});
}