Bootstrap 模态 DOM 元素在 Angular 单元测试中不可用 [英] Bootstrap modal DOM element not available in Angular unit test
本文介绍了Bootstrap 模态 DOM 元素在 Angular 单元测试中不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在打开 Bootstrap 对话框时,它的 HTML 被放置在 DOM 根正下方 <身体 >.
On opening Bootstrap dialog its HTML is placed in the DOM root right below < body >.
目标元素在 Angular 根组件之外,这就是单元测试中的下一次查询没有结果的原因.
The target element is outside of the Angular root component and that's a reason why the next querying in unit test gets no result.
const modalContent: HTMLElement
= fixture.nativeElement.querySelector('.modal-content');
有没有办法用以这种方式实现的模态窗口编写组件 DOM 测试?或者更具体地说,我如何在此处查询打开的模态窗口的 HTML 以便测试其内容.
Is there a way to write component DOM test with modal window implemented in such way? Or to be more concrete how can I query here for HTML of opened modal window in order to test its content then.
推荐答案
我想这个应该可行:
const modalContent: HTMLElement = document.body.querySelector('.modal-content');
这篇关于Bootstrap 模态 DOM 元素在 Angular 单元测试中不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文