简体   繁体   中英

Bootstrap modal DOM element not available in Angular unit test

On opening Bootstrap dialog its HTML is placed in the DOM root right below < body >.

这里是

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');

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.

I suppose this one should work:

const modalContent: HTMLElement = document.body.querySelector('.modal-content');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM