0.9.5
0.9.4 is unlisted in gallery. It was tagged on incorrect commit.
What is new since 0.9.3
PowerShell 2 and cross-platform compatibility
Assert is now compatible PowerShell 2, 3, 4, 5 and PowerShell Core 6 on Linux and MacOS 🎉🍾🥂🧁
Only compare what is on Expected
Use -ExcludePathsNotOnExpected
to compare only what is defined on Expected. This is extremely useful when you are only interested in a subset of data on the object, and especially when the object contains volatile data such as counters.
$expected = [PSCustomObject] @{
Status = 'OK'
Caption = 'Microsoft Windows 10 Pro N'
WindowsDirectory = 'C:\Windows'
}
$actual = Get-CimInstance -class win32_OperatingSystem
$options = Get-EquivalencyOption -ExcludePathsNotOnExpected
Assert-Equivalent -Expected $expected -Actual $actual -Option $options
# compare the results with
# Assert-Equivalent -Expected $expected -Actual $actual
Exclude paths, and wildcarded paths
Use -ExcludePath
option to exclude a path from the comparison. This is useful when there is a small set of properties to skip, because it allows your tests to detect changes in the actual object if any property is added, so for example a great opportunity to use this would be for REST api the uses CreatedAt
timestamps on objects.
Here a more local example that skips Type property on any Language key in the hashtable. Notice that we are using traversing different types of objects (PSObject and Hashtable) and are still able to define the path easily.
$expected = [PSCustomObject] @{
ProgrammingLanguages = @{
Language1 = [PSCustomObject] @{
Name = "C#"
Type = "OO"
}
Language2 = [PSCustomObject] @{
Name = "PowerShell"
Type = "Scripting"
}
}
}
$actual = [PSCustomObject] @{
ProgrammingLanguages = @{
Language1 = [PSCustomObject] @{
Name = "C#"
}
Language2 = [PSCustomObject] @{
Name = "PowerShell"
}
}
}
$options = Get-EquivalencyOption -ExcludePath "ProgrammingLanguages.Language*.Type"
Assert-Equivalent -Actual $actual -Expected $expected -Options $options
Breaking changes
There should be none, but the api for Options is not final, and will most likely get placed on Assert-Equivalent
directly in release 1.0.0
.