Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"New-MockObject" adding multiple methods - leads to error!? #2067

Closed
nohwnd opened this issue Aug 31, 2021 Discussed in #2066 · 0 comments
Closed

"New-MockObject" adding multiple methods - leads to error!? #2067

nohwnd opened this issue Aug 31, 2021 Discussed in #2066 · 0 comments

Comments

@nohwnd
Copy link
Member

nohwnd commented Aug 31, 2021

Discussed in #2066

Originally posted by TRUMPF-TobiH August 30, 2021
Hello Together,
sorry if the question is stupid, I am still new to Pester.
I am trying to mock an object with multiple methods, which results in an error.
Here is the code snippet directly from powershell:

$test = New-MockObject -Type 'Net.Sockets.TcpClient' -Methods  @{
    Connect = { param($Server, $Port)"connect" };
    Close   = { param($Server, $Port)"close" }
}

Error Message:

InvalidOperation: C:\Program Files\PowerShell\Modules\Pester\5.3.0\Pester.psm1:12499:13
 Line |
12499 |              $mockState[$historyName] = @{
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      | Unable to index into an object of type "System.Management.Automation.PSNoteProperty".

Works fine with single method:

$test = New-MockObject -Type 'Net.Sockets.TcpClient' -Methods  @{
    Connect = { param($Server, $Port)"connect" }
}

Also fine with multiple properties:

$test = New-MockObject -Type 'Net.Sockets.TcpClient' -Properties  @{
    Connect = "connect" ;
    Close   = "close"
}

Using Pester Version 5.3.0 from psgallery on Windows Powershell Core 7.1.4

Thanks already for feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants