Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Aug 20, 2024
1 parent ed98615 commit b32c713
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions tests/Unit/Public/Assert-BlockString.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,60 @@ AfterAll {

Describe 'Assert-BlockString' {
It 'Should pass when Actual and Expected are equal strings' {
$Actual = 'Test string'
$Expected = 'Test string'
{ Assert-BlockString -Actual $Actual -Expected $Expected } | Should -Not -Throw
$mockActual = 'Test string'
$mockExpected = 'Test string'

{ Assert-BlockString -Actual $mockActual -Expected $mockExpected } | Should -Not -Throw
}

It 'Should throw when Actual and Expected are different strings' {
$Actual = 'Test string'
$Expected = 'Different string'
{ Assert-BlockString -Actual $Actual -Expected $Expected } | Should -Throw
$mockActual = 'Test string'
$mockExpected = 'Different string'

{ Assert-BlockString -Actual $mockActual -Expected $mockExpected } | Should -Throw
}

It 'Should throw when Actual is not a string' {
$Actual = 12345
$Expected = 'Test string'
{ Assert-BlockString -Actual $Actual -Expected $Expected } | Should -Throw
$mockActual = 12345
$mockExpected = 'Test string'

{ Assert-BlockString -Actual $mockActual -Expected $mockExpected } | Should -Throw
}

It 'Should throw when Actual is string array' {
$Actual = @('1','2')
$Expected = 'Test string'
{ Assert-BlockString -Actual $Actual -Expected $Expected } | Should -Throw
$mockActual = @('1','2')
$mockExpected = 'Test string'

{ Assert-BlockString -Actual $mockActual -Expected $mockExpected } | Should -Throw
}

It 'Should include Because message in the error' {
$Actual = 'Test string'
$Expected = 'Different string'
$mockActual = 'Test string'
$mockExpected = 'Different string'
$Because = 'this is a test'
{ Assert-BlockString -Actual $Actual -Expected $Expected -Because $Because } | Should -Throw -ExpectedMessage '*because this is a test*'

{
Assert-BlockString -Actual $mockActual -Expected $mockExpected -Because $Because
} | Should -Throw -ExpectedMessage '*because this is a test*'
}

It 'Should handle pipeline input' {
$Expected = 'Test string'
$mockExpected = 'Test string'

$scriptBlock = {
'Test string' | Assert-BlockString -Expected $Expected
'Test string' | Assert-BlockString -Expected $mockExpected
}

{ & $scriptBlock } | Should -Not -Throw
}

It 'Should be able to be called using its alias' {
$Expected = 'Test string'
$mockExpected = 'Test string'

$scriptBlock = {
'Test string' | Should-BeBlockString -Expected $Expected
'Test string' | Should-BeBlockString -Expected $mockExpected
}

{ & $scriptBlock } | Should -Not -Throw
}
}

0 comments on commit b32c713

Please sign in to comment.