I was wondering if it is possible to add a DOM element to the test DOM before running tests. I'm new to testing, but something like
fixture.debugElement.prepend('div')
might work. However, I understand that this approach may indicate a design flaw in my code. If you would like more explanation on why I am asking this question, please see below.
Reason for needing this:
In my application, I have a text ticker directive similar to a previous version found at this link. For this directive to work properly, I need to calculate the length of the text. To do this, I create a ghost element and place it in my AppComponent as shown below:
@Component({
selector: 'app-root',
template: `
<div id="ghost"></div> <!-- THIS ELEMENT IS NEEDED -->
<div class="main-area">
<router-outlet></router-outlet>
</div>
`,
styleUrls: ['./app.component.scss']
})
Unfortunately, this element needs to be positioned where it is due to CSS requirements for proper measurement. However, this means that it is not accessible in my tests.