github pester/Pester 4.7.0-beta1

latest releases: 6.0.0-alpha5, 6.0.0-alpha4, 6.0.0-alpha3...
pre-release5 years ago

What is new since 4.6.0?

Thanks to @renehernandez for these awesome improvements to Mock!

Mock parameter filter can use aliases

Using parameter aliases in Mock ParameterFilters was a long requested feature, and it is finally here.

In the example below you can see the alias Last being used in the parameter filter, and then used from two mocks. One using the actual parameter name Tail and the other one using the parameter alias Last:

Describe "Get-Content" {   
    It "Filters on parameter alias" {
        Mock Get-Content -ParameterFilter {$Last -eq 100} { "mock1" }
        
        Get-Content -Path . -Tail 100 | Should -Be "mock1"
        Get-Content -Path . -Last 100 | Should -Be "mock1"
    }
}

Mock aliases executables on Windows without .exe extension

Mocking an external command on Windows will now alias it with and without .exe. Here is an example of mocking notepad.exe.

Describe "Notepad" {   
    It "Aliases notepad" {
        Mock Notepad { "mock1" }

        notepad.exe | Should -Be "mock1"
        notepad | Should -Be "mock1"        
    }
}

Mocking Get-Module no longer fails

Mocking Get-Module failed because the proxy function that PowerShell generates is conflicting with $PSEdition readonly variable. But now the parameter variable is renamed to $_PSEdition and aliased back to PSEdition. This allows you to mock Get-Module as you would with any other function. The only difference is that in ParemeterFilter you now need to use the $_PSEdition` if you wish to filter by it. Here is an example:

Describe "Get-Module" {
    It "Filtering PSEdition" {
        Mock Get-Module -ParameterFilter { $_PSEdition -eq "Desktop" } { "mock1" }
    
        Get-Module -PSEdition Desktop -ListAvailable | 
            Should -Be "mock1"
    }
}

Don't miss a new Pester release

NewReleases is sending notifications on new releases.