This repo is now archived as the functionality exists directly in Pester: https://pester.dev/docs/usage/assertions#be
This module provides additional assertions for Pester to help with testing array contents
Also see PesterMatchHashtable for hashtable assertions.
You can install PesterMatchArray via the PowerShell Gallery
Install-Module -Name PesterMatchArray
Because Pester works with the pipeline to give a nice syntax for tests, and PowerShell uses the pipeline to pass sequences through functions/cmdlets, the syntax for assertions of arrays with Pester is a little bit unintuitive. In particular, note the comma at the start of the assertion examples below.
MatchArrayOrdered compares two arrays. They are deemed to match if they have the same contents in the same order.
Describe "MatchArrayOrdered examples" {
It "single item arrays match" {
,@("a") | Should MatchArrayOrdered @("a")
}
It "arrays with the same contents match" {
,@("a", 1) | Should MatchArrayOrdered @("a",1)
}
It "arrays with the same contents in different orders do not match" {
,@("a", 1) | Should Not MatchArrayOrdered @(1,"a")
}
}
MatchArrayUnordered compares two arrays. They are deemed to match if they have the same contents regardless of the order of the items.
Describe "MatchArrayUnordered examples" {
It "single item arrays match" {
,@("a") | Should MatchArrayUnordered @("a")
}
It "arrays with the same contents match" {
,@("a", 1) | Should MatchArrayUnordered @("a",1)
}
It "arrays with the same contents in different orders match" {
,@("a", 1) | Should MatchArrayUnordered @(1,"a")
}
}
Pushed to PowerShell Gallery
Fix #4 (BUG: arrays with the same items in different quantities do not fail unordered assertion)
Pushed to PowerShell Gallery
Updated to work with Pester v4 (tested on 4.0.5 pre-release)
Pushed to PowerShell Gallery
Initial version of PesterMatchArray that is split out from other projects