所以我有 jquery 事件处理程序附加到window
,我在willDestroyElement
钩子中删除它,但是在测试触发回调之后立即调用事件(在测试修复中添加一些延迟,但它似乎不正确......)
_detachHandlers: Ember.on('willDestroyElement', function() {
$(window).off('resize');
})
测试:
this.render(hbs`
{{#if show}}
{{#my-component timesCalled=(mut timesCalled)}}
<button class='button'>Click me!</button>
{{/my-component}}
{{/if}}
`);
assert.ok(this.$('button.button').length, 'renders button');
run(() => $(window).trigger('resize'));
assert.equal(this.get('timesCalled'), 1, "callback worked one time");
run(() => this.set('show', false));
assert.notOk(this.$('button.button').length, 'component disappears');
run(() => $(window).trigger('resize'));
assert.equal(this.get('timesCalled'), 1, "callback detached and counter doesn't change");
我想我需要在运行中包装一些东西,但是什么?尝试了许多似乎有意义但没有奏效的方法。