How do I test enum
using the Powershell unit test Pester framework ?
What I get from the test subject seems to be a string, not my correct one enum
.
Testresult
Test results result in an error. What I received was Apple
, not my listing [FruitType]::Apple
.
...
Expected {[FruitEnum]::Apple}, but got {Apple}.
6: $res.TheFruit | Should -Be [FruitEnum]::Apple
...
Fruit.psm1
The Powershell module here makes enum "public" and exports a method that returns an object with my Fruit enumeration.
enum FruitEnum{
Apple
}
function Get-Fruit{
return @{
TheFruit = [FruitEnum]::Apple
}
}
Export-ModuleMember -Function Get-Fruit
Fruit.Tests.ps1
The Pester test calls using
to get an enumeration, calls the test person and checks the result.
using module .\Fruit.psm1
Import-Module .\Fruit.psm1 -Force
Describe "Get-Fruit" {
It "returns an enum" {
$res = Get-Fruit
$res.TheFruit | Should -Be [FruitEnum]::Apple
}
}
source
share