2013-02-28 61 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(); 
    }); 
});