こんにちは、親愛なるコミュニティのメンバーです。チェックボックスのクリックイベントの処理をテストするときに、IE 8 でのみ問題が発生しています。問題を確認できる JSBIN リンクは次のとおりです: http://jsbin.com/jicijilo/1/
どうやらモジラだけがこれらのような生のソースを処理できるので、モカアダプターとexpectjsソースコード全体を挿入しなければならなかったことを申し訳ありませんhttps://raw.githubusercontent.com/teddyzeenny/ember-mocha-adapter/master/adapter.js
テスト自体は非常に単純です。質問のリストがあり、各質問にはブール値のアクティブな属性があります。すべての質問のこの「アクティブ」属性を切り替えるヘッダーチェックボックスがあります。ただし、ie8 では、クリック ヘルパーを使用してチェックボックスをクリックすると、オブザーバーがトリガーされないようです。テストのコア コードは次のとおりです。
<script>
//APPLICATION CODE STARTS HERE
window.AS = Ember.Application.create({
rootElement: '#ember-testing'
});
mocha.setup('bdd');
Ember.onLoad('Ember.Application', function(Application) {
Application.initializer({
name: 'tests',
initialize: function(container, application) {
Ember.testing = true;
}
});
});
Ember.Test.adapter = Ember.Test.MochaAdapter.create();
AS.setupForTesting();
AS.ApplicationAdapter = DS.FixtureAdapter.extend({simulateRemoteResponse: false});
AS.injectTestHelpers();
AS.Router.map(function() {
this.resource('questions', {path: '/'});
});
AS.Question = DS.Model.extend({
name: DS.attr('string'),
active: DS.attr('boolean')
});
AS.Question.FIXTURES = [
{
"id": 1,
"name": "What is your age?",
"active": false
},
{
"id": 2,
"name": "What is your name?",
"active": false
}
];
AS.QuestionsRoute = Ember.Route.extend({
model: function(params) {
return this.get('store').find('question');
}
});
AS.QuestionsController = Ember.ArrayController.extend({
toggleAll: false,
onToggleAllChange: function(){
var toggleAll = this.get("toggleAll");
this.get('content').forEach(function(question){
question.set("active", toggleAll);
});
}.observes('toggleAll')
});
</script>
<script>
describe("Testing", function() {
beforeEach(function() {
AS.reset();
visit("/");
});
it("test header toggle", function() {
click($("input[name='toggleAll']")).then(function() {
var chkd = $("input[name='toggleAll']")[0].checked;
$(".question input").each(function(index, dom){
expect(dom.checked).to.be(chkd);
});
});
});
});
$(document).ready(function() {
mocha.run();
});
</script>
</head>
<body>
<script type="text/x-handlebars" data-template-name="questions">
<div>{{input type="checkbox" name="toggleAll" checked=toggleAll}} Toggle active</div>
{{#each}}
<div class="question">{{input type="checkbox" checked=active}} {{name}}</div>
{{/each}}
</script>
<div id="mocha"></div>
<div id="ember-testing" style="border:1px solid #CCC;"></div>
</body>
テストはie8で失敗しますが、チェックボックスを手動でクリックすると、オブザーバーがトリガーされます。あなたの助けは大歓迎です。ありがとう、ディー