如何在运行测试时让ember用户使用FixtureAdapter?
我认为下面的代码会这样做,但事实并非如此,api调用仍在进行中。
// tests / helpers / start-app.js
Ember.run(function(){
App = Application.create(attributes);
App.setupForTesting();
App.injectTestHelpers();
// .create doesn't work either
App.ApplicationAdapter = DS.FixtureAdapter.extend({
queryFixtures: function(fixtures, query) {
console.log('querying fixtures');
var key = Object.keys(query)[0];
return fixtures.filterBy(key, +query[key]);
}
});
});
在setup()
测试方法中,我可以看到自定义夹具适配器已设置。
module('Acceptance: AssignmentMenu', {
setup: function() {
App = startApp();
// verify the FixtureAdapter is being used
var adapter = App.ApplicationAdapter.create();
console.log('queryFixtures => ', adapter.queryFixtures); // method does exist
session = App.__container__.lookup('service:session');
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
以下是导致调用外部API的store.find
调用
import AppRoute from "./app";
export default AppRoute.extend({
model: function() {
return this.store.find('class').then(function(classes) {
return classes.sortBy('name');
});
}
});
如果适配器的设置在app/adapaters/application.js
文件中完成,则上述所有内容都会通过测试,因此所有必需的灯具都已到位。