Closed webmapLee closed 9 months ago
it can't work when use aysnc/await,but loadModules return a Promise...
Hi @webmapLee you'll need to provide a simple github repo that reproduces the problem. This looks like you are mixing ES modules from @arcgis/core
with our ArcGIS CDN, which uses AMD modules, along with TypeScript types from arcgis-js-api
. Note that combining ESM with AMD modules within a single application won't work. https://developers.arcgis.com/javascript/latest/tooling-intro/#compare-amd-and-es-modules.
I'm not sure what framework you are using, but here's a Angular/TypeScript/Jest example using @arcgis/core: https://github.com/andygup/angular-jsapi-jest
now i can run esri-loader/loadModules test case with jest, but i can only use it like this:
test('arcgis 模块调用', () => {
arcgisApiRequests(['esri/Map']).then((loadedModules) => {
console.log(loadedModules)
})
})
i can't use async await,like this:
test('arcgis 模块调用', async () => {
const [Map] = arcgisApiRequests(['esri/Map'])
console.log(Map)
})
I don't know if this is the same, but on ArcGIS Charts we get the following error running jest:
TypeError: utils.Promise is not a constructor
.
I believe it is happening because of this line in the esri-loader repo.
Which only uses window['Promise']
when running in the browser, otherwise the utils.Promise
is set to undefined
, which results in the type error seen above.
Is there workaround available on our end, or any way this could be changed on your end to allow using esri-loader with jest?
@nel11211 we'll need a repro case. I'm not familiar with ArcGIS Charts, are they running the latest version of the ArcGIS JS API?
@nel11211 we'll need a repro case. I'm not familiar with ArcGIS Charts, are they running the latest version of the ArcGIS JS API?
We are using arcgis-js-api@next
(version is 4.23.0-next.20220316
), and esri-loader version 3.3.0
. The simplest description of our repro is something like this:
loadModules
from esri-loader
and calls await loadModules(...)
at some point.TypeError: utils.Promise is not a constructor
.Closing.
i want to know how to test esri-loader with jest,when i test esri-loader with jest , throw timeout errors, like:
my function:
my test case:
my tsconfig.json
my jest.config.js