【问题标题】:Ember + Mocha: Test can't access storeEmber + Mocha:测试无法访问商店
【发布时间】:2014-03-14 11:25:01
【问题描述】:

我的 Mocha-Tests 无法访问商店。我拼凑了一个非常简单的 JSbin。我希望测试能够访问 Fixtures。我错过了什么?

http://jsbin.com/denomilu/9/edit?js,output

var expect = chai.expect;
window.App = Ember.Application.create(); 
App.injectTestHelpers();
App.setupForTesting();
App.ApplicationAdapter = DS.FixtureAdapter.extend({
    simulateRemoteResponse: false
});

App.Group = DS.Model.extend({
    title: DS.attr('string') 
});

App.Group.FIXTURES = [
  { "id": 1, "title": "Test 1"}
];

describe('Test', function() {

    beforeEach(function(){
        App.reset();
    });

    it("finds the fixture", function () {
      Ember.run(function(){
        var title = App.__container__.lookup('store:main').find('group', 1).get('title');
        console.log(title);
        expect(title).to.equal("Test 1");
      });
    });

});

$(document).ready(function() {
    mocha.run();
});

谢谢!

【问题讨论】:

    标签: ember.js ember-data mocha.js


    【解决方案1】:

    事实证明它确实有效。唯一的事情是: find 返回一个承诺。以下代码有效:

    http://jsbin.com/denomilu/14/edit?js,output

    it("finds the fixture", function () {
      Ember.run(function(){
        App.__container__.lookup('store:main').find('group', 1).then(function(group){
          expect(group.get('title')).to.equal("Test 1");
        });
      });
    });
    

    【讨论】:

      猜你喜欢
      • 2018-01-23
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 2016-01-25
      • 2019-03-03
      • 2021-10-23
      • 2021-05-07
      • 2015-11-09
      相关资源
      最近更新 更多