Pester and testing for listing

How do I test enumusing 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 usingto 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
    }
}
+4
source share
1 answer

Pester , , :

($res.TheFruit -eq [FruitEnum]::Apple) | Should Be True

, , , True, , Should , -, , , .

, , :

$res.TheFruit.GetType().Fullname | Should Be "FruitEnum"
+4

Source: https://habr.com/ru/post/1691707/


All Articles