Skip to content

Mocked functions aren't properly identified #2663

@iRon7

Description

@iRon7

Checklist

What is the issue?

use case

The Build-Module I create allows for importing the current stable module and test for a any new prototype cmdlet (see: Cmdlet Prototype Pester testing) by mocking the prototype on top of the actually module.

This works fine, except that it doesn't mention the mocked function in the pester messages.
Meaning that I get messages like:

[-] Test-Object.References.[V] Buyer 53ms (49ms|4ms)
 PropertyNotFoundException: The property 'CaseMatters' cannot be found on this object. Verify that the property exists.
 at GetReference, <No file>:300
 at TestNode, <No file>:591
 at QueryChildNodes, <No file>:789
 at TestNode, <No file>:725
 at <ScriptBlock><Process>, <No file>:813

Expected Behavior

For e.g. the Steps To Reproduce below, I would expect a more descriptive location like at <Get-Date>, .\Mock.ps1:4 or at <mocked Get-Date>, .\Mock.ps1:4 rather than a general <ScriptBlock>, .\Mock.ps1:4 identification.
And possibly a beter definition for <No file> and <Process (as shown above).

Steps To Reproduce

Describe 'Test' {

    BeforeAll {
        Mock Get-Date { 1 / 0 }
    }

    Context 'Context' {
        It 'It' {
            Get-Date | Should -be Something
        }
    }
}

Produces:

Starting discovery in 1 files.
Discovery found 1 tests in 42ms.
Running tests.
[-] Test.Context.It 123ms (123ms|1ms)
 DivideByZeroException: Attempted to divide by zero.
 RuntimeException: Attempted to divide by zero.
 at <ScriptBlock>, .\Mock.ps1:4
Tests completed in 291ms
Tests Passed: 0, Failed: 1, Skipped: 0 NotRun: 0

Describe your environment

Pester version : 5.5.0 C:\Users\Gebruiker\Documents\PowerShell\Modules\Pester\5.5.0\Pester.psm1
PowerShell version : 7.5.3
OS version : Microsoft Windows NT 10.0.26100.0

Possible Solution?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions