lundi 8 mai 2017

Ember JS tutorial: TypeError: Cannot read property 'maps' of undefined

I am currently running through the official EmberJS tutorial on their website and I'm on this part. Everything works perfectly in the app itself when I run ember serve but the problem is when I run the unit tests for the new service. I am running ember test --server and I get an error that I took a screenshot of below:

enter image description here

The 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, my understanding is that this.subject({ cachedMaps: stubCachedMaps }) will set up all the maps for me but it seems the service itself might be undefined, leading to no property maps. Is this right? What could be causing this?

System specs from running ember --version:

  • ember-cli: 2.13.0
  • node: 6.8.1
  • os: darwin x64



Aucun commentaire:

Enregistrer un commentaire