< Back

Assert-That

Sun Jan 12, 2020 5:51 pm

NAME Assert-That



SYNOPSIS

Asserts that an object meets certain conditions and throws an exception when they aren't.





SYNTAX

Assert-That [-InputObject] <Object> -Throws <Type> [-AndMessageMatches <String>] [[-Message] <String>]

[<CommonParameters>]



Assert-That [-InputObject] <Object> -DoesNotThrowException [<CommonParameters>]





DESCRIPTION

The `Assert-That` function checks that a given set of condiions are true and if they aren't, it throws a

`Blade.AssertionException`.





PARAMETERS

-InputObject <Object>

The object whose conditions you're checking.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Throws <Type>

The type of the exception `$InputObject` should throw. When this parameter is provided, $INputObject should be

a script block.



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-AndMessageMatches <String>

Used with the `Throws` switch. Checks that the thrown exception message matches a regular rexpression.



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DoesNotThrowException [<SwitchParameter>]

Asserts that the script block given by `InputObject` does not throw an exception.



Required? true

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Message <String>

The message to show when the assertion fails.



Required? false

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Assert-That { throw 'Fubar!' } -Throws [Management.Automation.RuntimeException]



Demonstrates how to check that a script block throws an exception.









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Assert-That { } -DoesNotThrowException



Demonstrates how to check that a script block doesn't throw an exception.











RELATED LINKS