Describe "ConvertTo-Html Tests" -Tags "CI" { BeforeAll { $customObject = [pscustomobject]@{"Name" = "John Doe"; "Age" = 42; "Friends" = ("Jack", "Jill")} $newLine = "`r`n" } function normalizeLineEnds([string]$text) { $text -replace "`r`n?|`n", "`r`n" } It "Test ConvertTo-Html with no parameters" { $returnObject = $customObject | ConvertTo-Html ,$returnObject | Should BeOfType System.Object[] $returnString = $returnObject -join $newLine $expectedValue = normalizeLineEnds @" HTML TABLE
NameAgeFriends
John Doe42System.Object[]
"@ $returnString | Should Be $expectedValue } It "Test ConvertTo-Html Fragment parameter" { $returnString = ($customObject | ConvertTo-Html -Fragment) -join $newLine $expectedValue = normalizeLineEnds @"
NameAgeFriends
John Doe42System.Object[]
"@ $returnString | Should Be $expectedValue } It "Test ConvertTo-Html as List" { $returnString = ($customObject | ConvertTo-Html -As List) -join $newLine $expectedValue = normalizeLineEnds @" HTML TABLE
Name:John Doe
Age:42
Friends:System.Object[]
"@ $returnString | Should Be $expectedValue } It "Test ConvertTo-Html specified properties" { $returnString = ($customObject | ConvertTo-Html -Property Name, Friends -As List) -join $newLine $expectedValue = normalizeLineEnds @" HTML TABLE
Name:John Doe
Friends:System.Object[]
"@ $returnString | Should Be $expectedValue } It "Test ConvertTo-Html using page parameters" { $returnString = ($customObject | ConvertTo-Html -Title "Custom Object" -Body "Body Text" -CssUri "page.css" -As List) -join $newLine $expectedValue = normalizeLineEnds @" Custom Object Body Text
Name:John Doe
Age:42
Friends:System.Object[]
"@ $returnString | Should Be $expectedValue } It "Test ConvertTo-Html pre and post" { $returnString = ($customObject | ConvertTo-Html -PreContent "Before the object" -PostContent "After the object") -join $newLine $expectedValue = normalizeLineEnds @" HTML TABLE Before the object
NameAgeFriends
John Doe42System.Object[]
After the object "@ $returnString | Should Be $expectedValue } }