Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Functions/Mock.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,23 @@ Describe "When calling Mock on existing function with matching unbound arguments
}
}

Describe 'When calling Mock on a function that has no parameters' {
function Test-Function { }
Mock Test-Function { return $args.Count }

It 'Sends the $args variable properly with 2+ elements' {
Test-Function 1 2 3 4 5 | Should Be 5
}

It 'Sends the $args variable properly with 1 element' {
Test-Function 1 | Should Be 1
}

It 'Sends the $args variable properly with 0 elements' {
Test-Function | Should Be 0
}
}

Describe "When calling Mock on cmdlet Used by Mock" {
Mock Set-Item {return "I am not Set-Item"}
Mock Set-Item {return "I am not Set-Item"}
Expand Down
3 changes: 2 additions & 1 deletion Functions/Mock.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ function MockPrototype {
$moduleName = $ExecutionContext.SessionState.Module.Name
}

$ArgumentList = @(Get-Variable -Name args -ValueOnly -Scope Local -ErrorAction SilentlyContinue)
$ArgumentList = Get-Variable -Name args -ValueOnly -Scope Local -ErrorAction SilentlyContinue
if ($null -eq $ArgumentList) { $ArgumentList = @() }

Invoke-Mock -CommandName $functionName -ModuleName $moduleName -BoundParameters $PSBoundParameters -ArgumentList $ArgumentList
}
Expand Down