Ember:在集成测试中测试组件的WillDestroyElement逻辑
Ember: Testing WillDestroyElement Logic of Component in an Integration Test
我有一个Ember组件。。。
Ember.Component.extend({
onDidInsertElement: function(){
var that = this;
Ember.run.scheduleOnce('afterRender', () => {
// Some code that sets up a jQuery plugin which attaches events etc
});
},
onWillDestroyElement: function(){
// Code that destroys the jQuery plugin (removing attached events etc)
}
}
这是我的集成测试:
test('it renders', function (assert) {
this.render(hbs`{{my-component }}`);
// Here some code to make sure the rendered state is ok
// then...
// ?? How to fire the "willDestroyElement" lifecycle hook?
}
假设我知道如何检查页面上是否存在jQuery插件事件(例如,使用此处描述的技术),那么我该如何在集成测试中测试拆卸逻辑呢?
您可以使用component.destroyElement
(其中提到它将调用willDestroyElement
钩子)或component.destroy
。
不访问组件实例的方法:
this.set('showComponent', true);
this.render(hbs(`{{if showComponent}}{{my-component}}{{/if}}`));
然后设置:
this.set('showComponent', false);
相关文章:
- React重新渲染但未显示正确的组件
- 不能从angular2中的子组件指定父组件中的数组
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- React组件等待所需道具进行渲染
- 如何创建带有插槽的vue js组件预加载程序
- KnockoutJS-组件-多个实例
- 如何更改reactjs中外部/独立组件的状态或属性
- 如何在react js中将值从一个组件发送到另一个组件
- React Native通过Navigator将用户输入数据传递到选项卡栏IOS中的组件
- React组件-设置页面标题
- 我的shareService在angular 2中发送值工作正常,但当我渲染我的另一个组件时,会获得默认值
- 如何在salesforce aura闪电组件中使用jQuery.val()
- 为react组件传递道具的最佳方式
- [Vue warn]:未能解析组件
- 如何控制组件'的createContent函数被激发
- react组件中的绑定方法
- 如何在react js中移动第二个组件
- 多个组件是如何实现的
- 组件生命周期问题/无法处理未定义的问题
- 如何在react路由器的组件中使用参数