我没有通过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();
});
谢谢!
答案 0 :(得分:1)
原来它确实有效。唯一的事情是:find返回一个promise。以下代码有效:
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");
});
});
});