Skip to content

Commit

Permalink
test: Add tests to ensure that errors were not thrown when getting an…
Browse files Browse the repository at this point in the history
…d writing tips
  • Loading branch information
deadlydog committed May 20, 2024
1 parent 53701a4 commit f04be35
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
17 changes: 17 additions & 0 deletions deploy/Invoke-SmokeTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@ Describe 'Get-PowerShellTip' {
$tip = Get-PowerShellTip
$tip | Should -Not -BeNullOrEmpty
}

It 'Should not return an error' {
$Error.Clear()
{ Get-PowerShellTip } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}

Context 'Given a valid tip ID' {
It 'Should return the tip with the specified ID' {
$tip = Get-PowerShellTip -Id '2023-07-16-powershell-is-open-source'
$tip.Id | Should -Be '2023-07-16-powershell-is-open-source'
}

It 'Should not return an error' {
$Error.Clear()
{ Get-PowerShellTip -Id '2023-07-16-powershell-is-open-source' } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty

}
}

Context 'Given an invalid tip ID' {
Expand Down Expand Up @@ -53,13 +66,17 @@ Describe 'Get-PowerShellTip' {
Describe 'Write-PowerShellTip' {
Context 'Given no parameters' {
It 'Should write a tip to the terminal without error' {
$Error.Clear()
{ Write-PowerShellTip } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}

Context 'Given a valid tip ID' {
It 'Should write the tip to the terminal without error' {
$Error.Clear()
{ Write-PowerShellTip -Id '2023-07-16-powershell-is-open-source' } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/tiPS/Public/Get-PowerShellTip.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,25 @@ Describe 'Get-PowerShellTip' {
$tip = Get-PowerShellTip
$tip | Should -Not -BeNullOrEmpty
}

It 'Should not return an error' {
$Error.Clear()
{ Get-PowerShellTip } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}

Context 'Given a valid tip ID' {
It 'Should return the tip with the specified ID' {
$tip = Get-PowerShellTip -Id '2023-07-16-powershell-is-open-source'
$tip.Id | Should -Be '2023-07-16-powershell-is-open-source'
}

It 'Should not return an error' {
$Error.Clear()
{ Get-PowerShellTip -Id '2023-07-16-powershell-is-open-source' } | Should -Not -Throw
$Error[0] | Should -BeNullOrEmpty
}
}

Context 'Given an invalid tip ID' {
Expand Down
6 changes: 5 additions & 1 deletion src/tiPS/Public/Write-PowerShellTip.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ Describe 'Write-PowerShellTip' {
}

Context 'Given no parameters' {
It 'Should write a tip' {
It 'Should write a tip without error' {
$Error.Clear()
{ Write-PowerShellTip } | Should -Not -Throw
Should -InvokeVerifiable # Verify that the Write-Host mock was called.
$Error[0] | Should -BeNullOrEmpty
}
}

Context 'Given a valid tip ID' {
It 'Should write the tip to the terminal without error' {
$Error.Clear()
{ Write-PowerShellTip -Id '2023-07-16-powershell-is-open-source' } | Should -Not -Throw
Should -InvokeVerifiable # Verify that the Write-Host mock was called.
$Error[0] | Should -BeNullOrEmpty
}
}

Expand Down

0 comments on commit f04be35

Please sign in to comment.