Ember JS Tutorial: TypeError: Unable to read property maps undefined

I am currently viewing the official EmberJS tutorial on my website, and I am in this part . Everything works fine in the application itself when I run ember serve, but the problem is that I run unit tests for a new service. I run ember test --serverand I get an error message that I took a screenshot below:

enter image description here

Unit test code:

import { moduleFor, test } from 'ember-qunit';
import Ember from 'ember';

const DUMMY_ELEMENT = {};

let MapUtilStub = Ember.Object.extend({
  createMap(element, location) {
    this.assert.ok(element, 'createMap called with element');
    this.assert.ok(location, 'createMap called with location');
    return DUMMY_ELEMENT;
  }
});

moduleFor('service:maps', 'Unit | Service | maps', {
  needs: ['util:google-maps']
});

test('should create a new map if one isnt cached for location', function (assert) {
  assert.expect(4);
  let stubMapUtil = MapUtilStub.create({ assert });
  let mapService = this.subject({ mapUtil: stubMapUtil });
  let element = mapService.getMapElement('San Francisco');
  assert.ok(element, 'element exists');
  assert.equal(element.className, 'map', 'element has class name of map');
});

test('should use existing map if one is cached for location', function (assert) {
  assert.expect(1);
  let stubCachedMaps = Ember.Object.create({
    sanFrancisco: DUMMY_ELEMENT
  });
  let mapService = this.subject({ cachedMaps: stubCachedMaps });
  let element = mapService.getMapElement('San Francisco');
  assert.equal(element, DUMMY_ELEMENT, 'element fetched from cache');
});

From the tutorial, I understand that it will this.subject({ cachedMaps: stubCachedMaps })configure everything for me maps, but it seems that the service itself may be undefined, which leads to the absence of a property maps. It is right? What could be the reason for this?

System specifications from launch ember --version:

  • ember-cli: 2.13.0
  • node: 6.8.1
  • os: darwin x64
+4
3

. , . , :

test('should use existing map if one is cached for location', 
  function(assert) {
    assert.expect(1);
    let stubCachedMaps = Ember.Object.create({
      sanFrancisco: DUMMY_ELEMENT
    });
    let stubMapUtil = MapUtilStub.create({ assert });
    let mapService = this.subject({ mapUtil: stubMapUtil, cachedMaps: stubCachedMaps });
    let element = mapService.getMapElement('San Francisco');
    assert.equal(element, DUMMY_ELEMENT, 'element fetched from cache');
});
+3

. @cythrawll , TypeError: Cannot read property 'maps' of undefined.

<script src="https://maps.googleapis.com/maps/api/js?v=3.22"></script>

in the test/index.htmlfile. Issue is already reported.

+1
source

Source: https://habr.com/ru/post/1676692/


All Articles