Unit Testing with WatchUtils

08-10-2022 06:23 AM
New Contributor III

Hey all - figured I'd reach out with a question I'm running into and see if anyone has some good ideas. I'm currently working on unit tests for my map service (Angular) and am having some problems running tests when incorporating watchUtils. Here's the pertinent code.

      whenFalse(this.view, 'stationary', () => {
        const beginScale: number = this.view.get('scale');
        const beginExtent: __esri.Extent = this.view.get('extent');
        whenTrueOnce(this.view, 'stationary', () => {
          const currentScale: number = this.view.get('scale');
          const endExtent: __esri.Extent = this.view.get('extent');
          const willWaitForIndividualAssets = this.view.zoom >= this.levelToRenderIndividualAssetsOnMap;
          const wasMovement = (currentScale !== beginScale || !beginExtent.equals(endExtent))
          if (wasMovement && !willWaitForIndividualAssets) {
          if (wasMovement && willWaitForIndividualAssets) {


 I've tried firing off a few events with no luck - so I'm wondering if anyone has any advice on how to get the watchUtils to actually trigger here within a unit test so I can test this stuff. Thanks!

0 Kudos
1 Reply
Esri Regular Contributor

Hi @rogenjh  Here's a basic codepen using reactiveUtils to show the concept: https://codepen.io/andygup/pen/ZExjMZq?editors=1000. MapView.interacting might be a better property for your use case. We recommend using reactiveUtils instead of watchUtils, here's the doc https://developers.arcgis.com/javascript/latest/api-reference/esri-core-reactiveUtils.html. watchUtils have been deprecated.

0 Kudos