Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Pester Test Fails Because Variable Returns Blank?

$
0
0

Hi everyone. I have an advanced function that does some stuff. I’ve stripped a majority of it out here since it isn’t really relevant. What’s important is that the function takes a parameter, ‘FirstName’, and the function has some logic that will reformat the first name to properly capitalize the first letter and make the other letters lowercase. I do something similar for the LastName. The function itself works properly and I get the desired result every time.

I’m trying to write a simple Pester test that will run the function, pass in a lowercase -FirstName (let’s use ‘john’ as an example), and verify that my function formatted it properly. The test fails saying that it expected {‘John’} but got back {}.

Here’s the relevant part of my function:

function Do-SomethingCool{ [CmdletBinding()] Param( [Parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="Enter the user's first name'")][Alias('GivenName')][string]$FirstName) $FirstName = $FirstName.Substring(0,1).toupper()+$FirstName.Substring(1).tolower() 

Here’s my Pester test:

It "Should properly format the first name" { Do-SomethingCool -FirstName 'john' $FirstName | Should BeExactly 'John' } 

Here’s the error I receive:

[-] Should properly format the first name 320ms Expected exactly: {John} But was: {} 17: $FirstName | Should BeExactly 'John' 

submitted by /u/cofonseca
[link] [comments]

The post Pester Test Fails Because Variable Returns Blank? appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles