Skip to content

Can't mock a function that takes pipeline input #2154

Open
@fsackur

Description

@fsackur

Describe your environment

Pester 5.3.1 on PSv5 and v7 on Win 10

Steps to reproduce

function outer
{
    1..3 | inner
}

function inner
{
    param
    (
        [Parameter(ValueFromPipeline)]$InputObject
    )

    # implicit end block, runs once
    "RETURN"
}

Describe "unmocked" {
    It "runs the end block" {
        (outer).Count | Should -Be 1
    }
}

Describe "mocked" {
    It "runs the end block" {
        Mock inner {"FOO"}
        (outer).Count | Should -Be 1
    }
}

Expected Behavior

Both tests pass

Current Behavior

Second test fails (because mock returns 1 object for each piped input)

Possible Solution? (optional)

Steppable pipeline. For sample code, run [System.Management.Automation.ProxyCommand]::Create([System.Management.Automation.CommandMetadata]::new((Get-Command New-Item)))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions