2013-02-28 66 views
0

任何人都可以在您自己的应用中测试Ember数据吗?测试Ember数据

我开始使用Fixtures适配器构建一个应用程序,这非常棒。但我想测试我的模型,并确保在构建时一切正常。

我有QUnit设置和运行,但我不想写服务器端,以验证数据模型进行调用。我想嘲笑适配器,看看是否调用了find方法,并从中返回一个新对象。稍后我会担心服务器端的实现。

任何想法?

这是我到目前为止(不工作):

test('MyModel should call find', 1, function(){ 
    App.TestAdapter = DS.Adapter.extend({ 
    find: function(store, type, id){ 
     ok(true, 'calls the find method'); 
     console.log('find: ', type, id); 
    } 
    }); 

    App.Store = DS.Store.extend({ 
    adapter: 'App.TestAdapater' 
    }); 

    myModel = App.MyModel.createRecord({ 
    name: 'Test', 
    period: 0 
    }); 

    // method that should call .find 
    myModel.currentObject(); 

}); 

回答

1

我结束了Konacha去。

最大的部分是:

before(function() { 
    Ember.run(function() { 
    App.initialize();  
    });  
}); 

afterEach(function() { 
    Ember.run(function() { 
    App.reset(); 
    }); 
});