mocking Get-Date

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
}
}
}

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

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