我正在尝试为使用 PrimeNG 表的角度组件创建单元测试。它在浏览器内与ngserve一起按预期工作,但在 Jasmine 测试中我无法获取表格的渲染 HTML。当我检查标记时,它只包含以下行:
<p-table class="testtable"><!--container--><!--container--></p-table>
我创建了一个仅包含静态数据的新组件来重现该问题:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
template: `
<p-table class="testtable" [value]="cars">
<ng-template pTemplate="header">
<tr>
<th>Vin</th>
<th>Year</th>
<th>Brand</th>
<th>Color</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>{{car.vin}}</td>
<td>{{car.year}}</td>
<td>{{car.brand}}</td>
<td>{{car.color}}</td>
</tr>
</ng-template>
</p-table>
`
})
export class TestComponent implements OnInit {
cars = [
{"brand": "VW", "year": 2012, "color": "Orange", "vin": "dsad231ff"},
{"brand": "Audi", "year": 2011, "color": "Black", "vin": "gwregre345"},
{"brand": "Renault", "year": 2005, "color": "Gray", "vin": …Run Code Online (Sandbox Code Playgroud)