AnsweredAssumed Answered

How is esriLoader (angular-esri-map) intended to be used in karma tests and what is its true purpose?

Question asked by jwerts on Apr 21, 2016
Latest reply on Apr 21, 2016 by jwerts


I'm trying to understand the esriLoader utility in angular-esri-map.  I'm not completely clear on the purpose of using it instead of dojo's require directly.  Furthermore, I've been completely unable to figure out how to use it in karma/mocha tests.  Specifically, the promises never return and mocha times out.  Previously, i was using the karma-dojo plugin and calling dojo's require directly which seems to work.  My big assumption here is that esriLoader should allow me to ditch the karma-dojo plugin.

 

I've tried many iterations of this without any luck (including some attempts to add in $rootScope.$apply() calls).  Here's just one of them:

 

describe('pointsModel spec', function() {
  var pointsModel;
  var esriLoader;

  beforeEach(module('jsapi4'));
  beforeEach(module('esri.core'));

  beforeEach(inject(function(_pointsModel_, _esriLoader_) {
    pointsModel = _pointsModel_;
    esriLoader = _esriLoader_;
  }));

  var Collection;
  beforeEach(function(done) {
    esriLoader.bootstrap().then(function() {
      esriLoader.require([
        "esri/core/Collection"
      ], function(_Collection) {
        Collection = _Collection;
        done();
      });
    });
  });

  describe('construction', function() {
    it('should inject pointsModel', function() {
      expect(pointsModel).to.not.be.undefined;
    });
  });

  describe("summary", function() {
    var points;

    beforeEach(function() {
      points = new Collection();
      pointsModel.setPoints(points);
    });

    it('should count indexes', function() {
      pointsModel.addPoints([
        { attributes: {index: 1}},
        { attributes: {index: 2}}
      ]);
      expect(pointsModel.getIndexSum()).to.equal(3);
    });
  });
});

Outcomes