mocking Get-Date

Welcome Forums Pester mocking Get-Date

Viewing 2 reply threads
  • Author
    Posts
    • #193198
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      Hi,

      I how can I mock Get-Date? below code does not work but if I change the mock commandname to Get-Test it works.

      Should the below code work?

      Thanks.

      Function Get-Test {
      Get-Date
      }
      
      Describe 'whatever' {
      Context 'test getdate'{
      it 'date should be dec1'{
      $Date = Get-Date 12/01/2019
      mock -CommandName Get-Date -MockWith {$Date}
      Get-Test | Should -Be $Date
      }
      }
      }
    • #196298
      Senior Moderator
      Topics: 8
      Replies: 1154
      Points: 4,012
      Helping Hand
      Rank: Community Hero

      Can you change the $Date variable to some other name and try ?

    • #196562
      Participant
      Topics: 1
      Replies: 1
      Points: -5
      Rank: Member

      Thank you.  works now.  Not sure why it didn't like $Date variable name.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.