angular find element by tag using fixture debugElement

To find an element by tag using the debugElement property of a component fixture in Angular, you can use the query method of the debugElement and pass it a By object with the css method and the tag name as arguments.

Here is an example of how you can find an element with the tag h2:

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { MyComponent } from './my.component';

describe('MyComponent', () => {
  let component: MyComponent;
  let fixture: ComponentFixture<MyComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [ MyComponent ]

  beforeEach(() => {
    fixture = TestBed.createComponent(MyComponent);
    component = fixture.componentInstance;

  it('should find an element with the tag h2', () => {
    const h2Element = fixture.debugElement.query(By.css('h2'));

This will search the template of the component for an element with the tag h2 and return the first matching element that it finds. If it does not find any matching elements, it will return null.