我目前正在通過其官方EmberJS教程在其網站上運行,我在this part上。當我運行ember serve
時,一切都在應用程序本身完美運行,但問題在於當我運行新服務的單元測試時。我運行ember test --server
,我得到的是我把下面的截圖錯誤:Ember JS教程:TypeError:無法讀取未定義的屬性「地圖」
單元測試代碼:
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');
});
從本教程中,我的理解是,this.subject({ cachedMaps: stubCachedMaps })
將成立所有maps
對我來說,但似乎服務本身可能是未定義的,導致沒有財產maps
。這是正確的嗎?什麼可能導致這個?從運行ember --version
系統規格:
- 燼-CLI:2.13.0
- 節點:6.8.1
- OS:達爾文64
是的,很像。我以爲我瘋了,所以我開始複製粘貼他們的代碼。這已破了。我會等待,看看有沒有人在這裏回答 – codyc4321