グローバルな状態を保存する単純なモデルクラスがあります
App.Person = Ember.Object.extend({
firstName: '',
lastName: ''
});
App.Person.reopenClass({
people: [],
add: function(hash) {
var person = App.Person.create(hash);
this.people.pushObject(person);
},
remove: function(person) {
this.people.removeObject(person);
},
find: function() {
var self = this;
$.getJSON('/api/people', function(response) {
response.forEach(function(hash) {
var person = App.Person.create(hash);
Ember.run(self.people, self.people.pushObject, person);
});
}, this);
return this.people;
}
});
RC6 と ember-testing を使用して App.reset() を呼び出すと、グローバル people 配列の状態がテスト間で維持されることに気付きます。テスト間でティアダウンが呼び出されたことを示すログが表示されますが、人数がクリアされていません。QUnit のティアダウンでこれをリセットするにはどうすればよいですか?
module('integration tests', {
setup: function() {
Ember.testing = true;
this.server = sinon.fakeServer.create();
this.server.autoRespond = true;
Ember.run(App, App.advanceReadiness);
},
teardown: function() {
this.server.restore();
App.reset(); //won't kill that global state ...
}
});
アップデート
RC6 で "/" ルートをモックしたい場合、xhr をモックした後にモデル フックが再び発火するのをバグが妨げます (これは RC7+ で修正されることを願っています)。