2015-10-04 46 views
0

我有一個Ember.js應用程序和Ember-CLI並使用Firebase。當我運行/測試中,我得到的唯一錯誤是:Ember-CLI測試:請在適配器上設置'firebase`屬性

Error: Please set the firebase property on the adapter. at init (http://localhost:4200/assets/vendor.js:99854:15) (...etc.)

我的application.js適配器代碼是繼餘燼安裝標準:

import Ember from 'ember'; 
import FirebaseAdapter from 'emberfire/adapters/firebase'; 

const { inject } = Ember; 

export default FirebaseAdapter.extend({ 
    firebase: inject.service(), 
}); 

和我的火力點:URL在設置environment.js文件。任何人都可以指出問題出在哪裏?應用程序本身運行良好。我意識到這是一個內置於inferfire的init函數中的錯誤響應,但這對我沒有幫助!我敢肯定它一定是小而明顯的啓動,但我仍然在學習曲線...

在此先感謝。

燼1.13.7 - 燼數據1.13.8 - 火力地堡2.3.0 - 餘燼1.5.0 - jQuery的1.11.3

回答

-1

我解決了這個通過修改測試/單元/適配器/應用test.js文件爲:

import { moduleFor, test } from 'ember-qunit'; 
import FirebaseAdapter from 'emberfire/adapters/firebase'; 

moduleFor('adapter:application', 'Unit | Adapter | application', { 
    // Specify the other units that are required for this test. 
    // needs: ['serializer:foo'] 
}); 

// Replace this with your real tests. 
test('it exists', function(assert) { 
    var adapter = FirebaseAdapter; //this.subject(); 
    assert.ok(adapter); 
}); 

希望能幫助別人!

+0

Sry基因,但由於適配器現在是FirebaseAdapter的一個實例,而不是你自己的適配器這是錯誤的。 – GerDner

2

我認爲在這種情況下指定丟失的單元與needs屬性更合適,因爲適配器無法注入Firebase服務。

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

moduleFor('adapter:application', 'Unit | Adapter | application', { 
    // Specify the other units that are required for this test. 
    needs: ['service:firebase'] 
}); 

// Replace this with your real tests. 
test('it exists', function(assert) { 
    let adapter = this.subject(); 
    assert.ok(adapter); 
}); 

希望這有助於您的測試。

0

因爲firebase服務需要配置,所以您還必須注入配置。

export default { 
    create(application) { 
    const config = getOwner(application)._lookupFactory('config:environment'); 

所以正確答案是:

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

moduleFor('adapter:application', 'Unit | Adapter | application', { 
    // Specify the other units that are required for this test. 
    needs: ['service:firebase', 'config:environment'] 
}); 

// Replace this with your real tests. 
test('it exists', function(assert) { 
    let adapter = this.subject(); 
    assert.ok(adapter); 
});