function requests user input as Pester Test runs

Welcome Forums Pester function requests user input as Pester Test runs

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 6 months ago.

  • Author
  • #77977

    Points: 45
    Rank: Member


    For unknown reasons when I attempt to test this function my terminal calls "Send-myEmail" and waits for user input to fill in parameters. I find this odd because I have it within the Mocks section of my pester test. Its as if running the Pester test is not mocking the "Send-myEmail" command. I have tried many different variations and cannot get this to work.

    FYI – "Send-myEmail" takes in all of the regular parameters "Send-Message" would but I made my own function and defaulted many of the parameters for easier use.

    Please help!

    function Search-RabbitSubString {
            [Parameter(Mandatory = $true,
                ValueFromPipeline = $true)]
        $expected_pattern = 'partitions":\[\]'
        Write-Verbose "Searching for $expected_pattern"
        $result = [bool] (Select-String -InputObject $substring -Pattern $expected_pattern)
        if ($result) {
            "Expected pattern in substring was found" | Add-ToRabbitLog
            return $true
        Write-Warning "Partition check failed!"
        "Some message" | Add-ToRabbitLog
        Send-MyEmail -subject "something" -body "something"
    Context 'Testing functionality' {
                mock Write-Warning -MockWith { return "Warning"}
                mock Add-ToRabbitLog -MockWith {}
                mock Send-MyEmail -mockwith { return "Success" }
                Search-RabbitSubString -Substring "fail"
                it 'should fail and send myemail' {
                    Assert-MockCalled -CommandName Write-Warning -Times 1
                    Assert-MockCalled -CommandName Add-ToRabbitLog -Times 1
                    Assert-MockCalled -commandName Send-MyEmail -Times 1
  • #78042

    Points: 22
    Rank: Member

    When you mock a command in Pester it doesn't completely nullify it. It creates a proxy command which copies all of it's parameters. I bet that your Send-MyEmail function has a mandatory parameter that's a credential.

The topic ‘function requests user input as Pester Test runs’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort