1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

unit test anchor link in Mat table cell

Discussão em 'Angular' iniciado por Arnab Mukherjee, Maio 26, 2025.

  1. Trying to unit test, whether a cell is having hyperlink or not.

    Not able to find the tag a via testHarness api.

    import { ComponentFixture, TestBed } from '@angular/core/testing';
    import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
    import { MatTableHarness } from '@angular/material/table/testing';
    import { HarnessLoader, parallel } from '@angular/cdk/testing';
    import { TableHarnessExample } from './table-harness-example';

    describe('TableHarnessExample', () => {
    let fixture: ComponentFixture<TableHarnessExample>;
    let loader: HarnessLoader;

    beforeEach(() => {
    fixture = TestBed.createComponent(TableHarnessExample);
    fixture.detectChanges();
    loader = TestbedHarnessEnvironment.loader(fixture);
    });

    fit('should show link in weight column', async () => {
    const table = await loader.getHarness(MatTableHarness);
    const firstRow = (await table.getRows())[0];
    const cells = await firstRow.getCells({ columnName: 'weight' });

    expect(await (await cells[0].host()).getProperty('a')).toBeDefined();
    });
    });


    Here is the stack blitz

    Continue reading...

Compartilhe esta Página