For JS API 4.33 and 4.34
I have notice that the componentOnReady() function for map legend component was not observed during runtime.
let arcgisMap = document.querySelector('arcgis-map');
let widget = document.createElement('arcgis-legend');
arcgisMap.appendChild(widget);
await widget.componentOnReady();
console.log(arcgisMap.querySelector('.arcgis-legend'));`.arcgis-legend` class is one of the style class names used for the rendered legend component element structure.
When monitoring code executing in the web browser's dev console, if you set breakpoints on lines 5 and 7, you will see that when execution is halted on line 7, the legend component has not yet been constructed, even though the component has supposedly reached ready state according to line 5. Is this a bug?
In 4.33, the selector is still `.esri-legend`. And in this case, `componentOnReady` only means the component code has loaded and properties/methods of the component are available to access. It doesn't mean that the data for the legend to get created is loaded. You can use the `arcgisReady` event of the legend if you want to do this in 4.33.
In 4.34 there is a `arcgis-legend` class, but it's in the shadowRoot and can't be queried via conventional means. So that won't work.