1
1
import { Component , ViewChild , input , type TemplateRef } from '@angular/core'
2
2
import { TestBed , type ComponentFixture } from '@angular/core/testing'
3
3
import { createColumnHelper } from '@tanstack/table-core'
4
- import { skip } from 'node:test'
5
4
import { describe , expect , test } from 'vitest'
6
5
import {
7
6
FlexRenderComponent ,
@@ -24,6 +23,20 @@ describe('FlexRenderDirective', () => {
24
23
test ( 'should render primitives' , async ( ) => {
25
24
const fixture = TestBed . createComponent ( TestRenderComponent )
26
25
26
+ // Null
27
+ setFixtureSignalInputs ( fixture , {
28
+ content : ( ) => null ,
29
+ context : { } ,
30
+ } )
31
+ expect ( ( fixture . nativeElement as HTMLElement ) . matches ( ':empty' ) ) . toBe ( true )
32
+
33
+ // Undefined
34
+ setFixtureSignalInputs ( fixture , {
35
+ content : ( ) => undefined ,
36
+ context : { } ,
37
+ } )
38
+ expect ( ( fixture . nativeElement as HTMLElement ) . matches ( ':empty' ) ) . toBe ( true )
39
+
27
40
// String
28
41
setFixtureSignalInputs ( fixture , {
29
42
content : 'My value' ,
@@ -45,19 +58,12 @@ describe('FlexRenderDirective', () => {
45
58
} )
46
59
expectPrimitiveValueIs ( fixture , 'My value 2' )
47
60
48
- // Null
61
+ // Set again to null to be sure content has been destroyed
49
62
setFixtureSignalInputs ( fixture , {
50
63
content : ( ) => null ,
51
64
context : { } ,
52
65
} )
53
- expectPrimitiveValueIs ( fixture , '' )
54
-
55
- // Undefined
56
- setFixtureSignalInputs ( fixture , {
57
- content : ( ) => undefined ,
58
- context : { } ,
59
- } )
60
- expectPrimitiveValueIs ( fixture , '' )
66
+ expect ( ( fixture . nativeElement as HTMLElement ) . matches ( ':empty' ) ) . toBe ( true )
61
67
} )
62
68
63
69
test ( 'should render TemplateRef' , ( ) => {
@@ -118,7 +124,7 @@ describe('FlexRenderDirective', () => {
118
124
119
125
// Skip for now, test framework (using ComponentRef.setInput) cannot recognize signal inputs
120
126
// as component inputs
121
- skip ( 'should render custom components' , ( ) => {
127
+ test . skip ( 'should render custom components' , ( ) => {
122
128
@Component ( {
123
129
template : `{{ row().property }}` ,
124
130
standalone : true ,
@@ -172,6 +178,7 @@ function expectPrimitiveValueIs(
172
178
fixture : ComponentFixture < unknown > ,
173
179
value : unknown
174
180
) {
181
+ expect ( fixture . nativeElement . matches ( ':empty' ) ) . toBe ( false )
175
182
const span = fixture . nativeElement . querySelector ( 'span' )
176
183
expect ( span ) . toBeDefined ( )
177
184
expect ( span . innerHTML ) . toEqual ( value )
0 commit comments