juneb / PesterTDD

Slides and code for my Pester presentations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Runtime Exception in Get-ParametersDefaultFirst

davegreen opened this issue · comments

Hello,

I recently updated the earlier version of the module help tests I borrowed from the code in this repository and ran into the following error when testing the updated code:

Method invocation failed because [System.Management.Automation.CommandParameterInfo] does not contain a method named 'op_Addition'.
At C:\Users\user\Desktop\Module.Help.Tests.ps1:137 char:7

  •                     $parameters += $_
    
  •                     ~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
    • FullyQualifiedErrorId : MethodNotFound

I had a bit of a look and the problem (in my case) appears to be in Get-ParametersDefaultFirst. The $parameters variable is set up as an empty array, but then overwritten with the contents of $defaultParameters (if populated). This appears to cause the behaviour that if there are any other parameters in $otherParameters, the code path will fail with the above error.