-
-
Notifications
You must be signed in to change notification settings - Fork 473
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
Asserting MockCalled causes an exception (from within Test-ParameterFilter) #1878
Comments
Here's a workaround for now I'm using: [Int]$SCRIPT:RemoveReleaseInvokeCount = 0
Mock -ModuleName Press Remove-GithubRelease { $SCRIPT:RemoveReleaseInvokeCount++ }
...
...
...
$SCRIPT:RemoveReleaseInvokeCount | Should -Be $RemoveCount |
Have you tried specifying @Glober777 Try: |
@JustinGrote: Is the original I believe this issue occurs while creating mocks inside However when the original command is external to the module where your mock is injected and you forget @nohwnd: Thoughts? I'm not very familiar with this mock-logic, but immediate (untested) thoughts would be to either:
|
I'll give it a shot and report back, I didn't know Should also had the module name scoping. |
@fflaten that worked like a charm for me. Makes sense that if the mock is in the module scope it would be tracking the invocations in the same scope.
|
@fflaten, works great! Thanks a ton! I wish it was more obvious when reading the error message. |
@fflaten I think 1) needs to be done because it is not change to the current Mock behavior. We can suggest using the -ModuleName in the error, and even in log. But I am also not sure why we are resolving the command again, instead of attaching info to the history and using it. (If I got what is happening from your description correctly). |
General summary of the issue
I'm testing a module where a member cmdlet calls Start-Job. In my test, I'm mocking Start-Job in the test (which works fine) however my tests fail on Assert-MockCalled (as well as on
Should -Invoke ...
) throwing an exception:Describe your environment
Pester version : 5.1.1 C:\Users\user1\Documents\PowerShell\Modules\Pester\5.1.1\Pester.psm1
PowerShell version : 7.1.1
OS version : Microsoft Windows NT 10.0.18363.0
Steps to reproduce
In my simplified repro project folder I have two subfolders:
In
MyModule
folder I have aMyModule.psm1
file with the following:In
Tests
folder I have the following (Repro.Tests.ps1
):Now, every time I either run
Invoke-Pester
or pressRun Tests
codelens I constantly get the abovementioned exceptionExpected Behavior
Test should succeed
Current Behavior
Test fails with an exception:
Exception
Possible Solution? (optional)
None
The text was updated successfully, but these errors were encountered: