Skip to content
Jon Wagner edited this page Feb 8, 2013 · 1 revision

Managing Mocks

First, make sure you have imported the PSMock module and enabled mocking in your script:

Import-Module PSMock
Enable-Mock | iex
function Hello { param ([string] $who) "Hello, $who" }

Removing Mocks

You can remove all of the mocks for a function with Remove-Mock.

Mock Hello { "goodbye" }
Hello				# "goodbye"
Remove-Mock Hello
Hello				# "Hello, "

Removing Cases

If you create more than one case for a mock, you can remove them individually if you name them:

Mock Hello { } -When { $who -eq 'bob' } -Name Bob
Mock Hello { "Howdy!" }
Hello bob			# nothing
Remove-Mock Hello -Case Bob
Hello bob			# "Howdy!"

Clearing all Mocks

You can clear all mocks in the current mock context with Clear-Mocks.

Mock Hello { "goodbye" }
Hello				# "goodbye"
Clear-Mocks
Hello				# "Hello, "

Re-importing the Module

If you force import the PSMock module, it will clear all mocks and mock contexts.

Import-Module PSMock -Force
# bye bye mocks