How to use the useFakeXMLHttpRequest function from sinon
Find comprehensive JavaScript sinon.useFakeXMLHttpRequest code examples handpicked from public code repositorys.
GitHub: will3/sinon
158 159 160 161 162 163 164 165 166
```javascript var xhr, requests; before(function () { xhr = sinon.useFakeXMLHttpRequest(); requests = []; xhr.onCreate = function (req) { requests.push(req); }; });
810
0
2
+ 3 other calls in file
GitHub: holidayextras/truman
69 70 71 72 73 74 75 76 77 78
.then((fixtures) => { // Want this available in memory. storageFixtures = fixtures // Sinon's fake XHR logs extra request info we'll need/want for our fixtures: sinon.useFakeXMLHttpRequest() // Always call through as we're recording and want to make the request: window.XMLHttpRequest.useFilters = true window.XMLHttpRequest.addFilter(() => true) // true = allow, false = stub
1
4
9
205 206 207 208 209 210 211 212 213 214
expect.exportAssertion( '<any> with xhr mocked out <object|array> <assertion>', function(expect, subject, requestDescriptions) { expect.errorMode = 'nested'; var mockedXhr = sinon.useFakeXMLHttpRequest(); if (!Array.isArray(requestDescriptions)) { requestDescriptions = [requestDescriptions]; } else {
1
0
1
17 18 19 20 21 22 23 24 25 26
const uid = 'odkSxashOmg9QeyRL2cRs00Jke12'; fs.readFile(`${__dirname}/../../app/signin.html`, 'utf8', async (err, data) => { describe('#signin functions', () => { before( () => { global.XMLHttpRequest = sinon.useFakeXMLHttpRequest(); guidSpy = sinon.spy(module, 'guidVal'); signInSpy = sinon.spy(module, 'signIn'); }); describe('#guidVal', () => {
1
0
3
+ 3 other calls in file
6 7 8 9 10 11 12 13 14 15 16
describe('Basic tests', function () { var that = this; beforeEach(function () { that.requests = []; that.xhr = sinon.useFakeXMLHttpRequest(); that.xhr.onCreate = function (xhr) { that.requests.push(xhr); }; });
0
0
0
GitHub: sabit/kibana
49 50 51 52 53 54 55 56 57 58
}); }); before(function () { sinon.useFakeXMLHttpRequest(); }); /*** Kick off mocha, called at the end of test entry files ***/
0
0
2
sinon.stub is the most popular function in sinon (5777 examples)