Open pldmgg opened 6 years ago
Here is a sample of how i understand it, The errorActionPreference is handled inside the Assert-throw so you don't need to include it.
Describe -Name 'Assert-Throw with Specific message' -Fixture {
It -name 'With AllowNonTerminatingError and specific Error Message and Throw' -test {
# This should fail due to the Write-Error being a non-terminating error and being skipped due to the -AllowNonTerminatingError Switch
{
Write-Error ('This should Error')
Throw ('Error Thrown')
} | Assert-Throw -AllowNonTerminatingError -ExceptionMessage ('This should Error')
}
It -name 'Without AllowNonTerminatingError and specific Error Message' -test {
{
Write-Error ('This should Error')
Throw ('Error Thrown')
} | Assert-Throw -ExceptionMessage ('This should Error')
}
It -name 'With AllowNonTerminatingError and specific Error Message and Throw' -test {
# This should pass
{
Write-Error ('This should Error')
Throw ('Error Thrown')
} | Assert-Throw -AllowNonTerminatingError -ExceptionMessage ('Error Thrown')
}
It -name 'Without AllowNonTerminatingError and specific Error Message' -test {
# This should fail because the message expected is the throw message but the error message produced
{
Write-Error ('This should Error')
Throw ('Error Thrown')
} | Assert-Throw -ExceptionMessage ('Error Thrown')
}
}
Hi there -
I'm relatively new to Pester (and consequently, new to your Module), but I had a question about how
Assert-Throw
is supposed to work.I've got a PowerShell Module called
TheThing.psm1
with the following functions:...and I setup my Pester Test like...
If I place all of the 'Do-Thing' function calls into a scriptblocks (i.e.
{Do-Thing} | Assert-Throw
etc.) like I've seen in some examples floating around, they all fail.Basically all I'm looking to do is test that a terminating error is thrown when
-ErrorAction Stop
is used and a non-terminating error is thrown when-ErrorAction Stop
is NOT used.Thoughts?