【问题标题】:Testing Ember Data测试 Ember 数据
【发布时间】:2013-03-12 04:21:43
【问题描述】:

谁有在你自己的应用中测试 Ember 数据的好例子?

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

我已经设置并运行了 QUnit,但我不想编写服务器端来验证数据模型是否进行了调用。我想模拟 Adapter 并查看是否调用了 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();

});

【问题讨论】:

    标签: ember-data


    【解决方案1】:

    我最终选择了Konacha

    最大的部分是:

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

    【讨论】:

      猜你喜欢
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      相关资源
      最近更新 更多