2015-10-04 44 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); 
});