forked from axios/axios
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "issue#2609 | Sasha | predictable axios requests (axios#2702)"
This reverts commit 62d6256.
- Loading branch information
xinjiexu
committed
Jul 2, 2021
1 parent
e9965bf
commit 8264cd0
Showing
5 changed files
with
22 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,19 @@ | ||
var axios = require('../../index'); | ||
|
||
describe('adapter', function () { | ||
beforeEach(function () { | ||
jasmine.Ajax.install(); | ||
}); | ||
|
||
afterEach(function () { | ||
jasmine.Ajax.uninstall(); | ||
}); | ||
|
||
it('should support custom adapter', function (done) { | ||
axios('/foo', { | ||
adapter: function barAdapter(config) { | ||
return new Promise(function dispatchXhrRequest(resolve) { | ||
var request = new XMLHttpRequest(); | ||
request.open('GET', '/bar'); | ||
|
||
request.onreadystatechange = function () { | ||
resolve({ | ||
config: config, | ||
request: request | ||
}); | ||
}; | ||
|
||
request.send(null); | ||
}); | ||
} | ||
}).catch(console.log); | ||
var called = false; | ||
|
||
getAjaxRequest().then(function(request) { | ||
expect(request.url).toBe('/bar'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should execute adapter code synchronously', function (done) { | ||
var asyncFlag = false; | ||
axios('/foo', { | ||
adapter: function barAdapter(config) { | ||
return new Promise(function dispatchXhrRequest(resolve) { | ||
var request = new XMLHttpRequest(); | ||
request.open('GET', '/bar'); | ||
|
||
request.onreadystatechange = function () { | ||
resolve({ | ||
config: config, | ||
request: request | ||
}); | ||
}; | ||
|
||
expect(asyncFlag).toBe(false); | ||
request.send(null); | ||
}); | ||
adapter: function (config) { | ||
called = true; | ||
} | ||
}).catch(console.log); | ||
|
||
asyncFlag = true; | ||
|
||
getAjaxRequest().then(function() { | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should execute adapter code asynchronously when interceptor is present', function (done) { | ||
var asyncFlag = false; | ||
|
||
axios.interceptors.request.use(function (config) { | ||
config.headers.async = 'async it!'; | ||
return config; | ||
}); | ||
|
||
axios('/foo', { | ||
adapter: function barAdapter(config) { | ||
return new Promise(function dispatchXhrRequest(resolve) { | ||
var request = new XMLHttpRequest(); | ||
request.open('GET', '/bar'); | ||
|
||
request.onreadystatechange = function () { | ||
resolve({ | ||
config: config, | ||
request: request | ||
}); | ||
}; | ||
|
||
expect(asyncFlag).toBe(true); | ||
request.send(null); | ||
}); | ||
} | ||
}).catch(console.log); | ||
|
||
asyncFlag = true; | ||
|
||
getAjaxRequest().then(function() { | ||
setTimeout(function () { | ||
expect(called).toBe(true); | ||
done(); | ||
}); | ||
}, 100); | ||
}); | ||
}); | ||
|
Oops, something went wrong.