ESRI JS Promise never resolves in intern tests
See original GitHub issueTest that include an ESRI JS Promise never resolves in intern tests and test fails with the following error:
TimeoutError: Timeout reached on chrome 75.0.3770.100 on Mac OS X - widgets/App/AppViewModel - should resolve ESRI Promise#
@ node_modules/intern/browser/remote.js:99:10665
Description
ESRI JS Promise never resolves but “classic” one does resolve and test succeed. For example, in any test suite add the following sample:
import esriRequest from "esri/request";
test("should resolve ESRI Promise", async () => {
return esriRequest('https://services.arcgisonline.com/arcgis/rest/services?f=json', {
responseType: "json"
}).then(function(response:any){
assert.equal(response.data.currentVersion, '10.6');
});
});
test("should resolve a Promise", () => {
function solvePromise(resolve:any, reject:any) {
const req = new XMLHttpRequest();
req.onreadystatechange = function(event) {
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status === 200) {
resolve(this.responseText);
}
}
};
req.open('GET', 'https://services.arcgisonline.com/arcgis/rest/services?f=json', true);
req.send(null);
}
var promise = new Promise(solvePromise);
return promise.then(function(value:string) {
assert.equal(JSON.parse(value).currentVersion, '10.6');
});
});
Test ‘should resolve ESRI Promise’ never resolve and fails with a timeout error but ‘should resolve a Promise’ does resolve and test succeeds.
Expected Behavior
ESRI JS Promise should resolve in intern tests and test should be successful.
Actual Behavior
ESRI JS Promise never resolves in intern test and test fails.
Possible Fix
No idea
Steps to Reproduce
- Include
import esriRequest from "esri/request";
in any test suite - Copy paste the 2 tests described above
- Run
npm test
Context
I cannot test any function that returns an ESRI JS Promise
Your Environment
- Version used: 4.11.0
- Browser Name and version: Chrome Version 75.0.3770.100
Any idea @odoe ? Thanks !
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Cannot test/run async code · Issue #23 · Esri/arcgis-js-cli · GitHub
It should be possible to test asynchronous job. Actual Behavior. 404 errors in console, and promise never resolved so tests never successful. Possible...
Read more >FeatureLayer Promise Doesn't Resolve - Esri Community
Solved: Hello All, I'm creating FeatureLayer objects from SubLayer objects in order to use them as sources in a Search widget.
Read more >Javascript promise never resolves - typescript - Stack Overflow
I would expect to see "test" after successful completion, but the promise never resolves. If I use await, it hangs on the await...
Read more >COVID-19 Vaccination and Testing; Emergency Temporary ...
Other types of work settings that were affected in resolved outbreaks included ... OSHA has never done so, and if it were to...
Read more >COVID-19 Vaccination and Testing; Emergency Temporary ...
OSHA-2021-0007] RIN 1218-AD42 COVID-19 Vaccination and Testing; ... people who are infected but never feel any symptoms of COVID-19), ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jason0x43 found the trick ! In webpack test config, output.publicPath should be set to ‘/~tmp/’.
Reading this post, I now understand why you wanted to wait for 4.12: nativ fetch will be used so my test might be successful. But I think the issue would still occur whenever a test will be executing ESRI JS code that will be doing a dynamic import just like “esri/request” is 4.11. Let’s see what see what the open issue on intern will say.