Программисты Html
Anonymous
Ячейка для ячейки на таблице мат в модуле
Сообщение
Anonymous » 26 май 2025, 11:48
Попытка провести единичный тест, имеет ли ячейку гиперссылку или нет.
Код: Выделить всё
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;
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();
});
});
Вот стек Blitz
Подробнее здесь:
https://stackoverflow.com/questions/796 ... table-cell
1748249298
Anonymous
Попытка провести единичный тест, имеет ли ячейку гиперссылку или нет.[code]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; 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(); }); }); [/code] Вот стек Blitz Подробнее здесь: [url]https://stackoverflow.com/questions/79638548/unit-test-anchor-link-in-mat-table-cell[/url]