Skip to main content
Version: v6

Should-BeBefore

This page was generated

Contributions are welcome in Pester-repo.

SYNOPSIS

Asserts that the provided [datetime] is before the expected [datetime].

SYNTAX

Now (Default)

Should-BeBefore [[-Actual] <Object>] [-Now] [-Because <string>]

FluentFromNow

Should-BeBefore [[-Time] <string>] [[-Actual] <Object>] -FromNow [-Because <string>]

FluentAgo

Should-BeBefore [[-Time] <string>] [[-Actual] <Object>] -Ago [-Because <string>]

Expected

Should-BeBefore [[-Expected] <datetime>] [[-Actual] <Object>] [-Because <string>]

DESCRIPTION

This assertion accepts either an expected [datetime] or a fluent relative time expression. Use -Now, -Ago, or -FromNow to compare against the current local time.

EXAMPLES

EXAMPLE 1

(Get-Date).AddDays(-1) | Should-BeBefore (Get-Date)

This assertion will pass, because the actual value is before the expected value.

EXAMPLE 2

(Get-Date).AddDays(1) | Should-BeBefore (Get-Date)

This assertion will fail, because the actual value is not before the expected value.

EXAMPLE 3

(Get-Date).AddMinutes(1) | Should-BeBefore 10minutes -FromNow

This assertion will pass, because the actual value is before the expected value.

EXAMPLE 4

(Get-Date).AddDays(-2) | Should-BeBefore -Time 3days -Ago

This assertion will pass, because the actual value is before the expected value.

PARAMETERS

-Actual

The actual [datetime] value.

Type: System.Object
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 2
IsRequired: false
ValueFromPipeline: true
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Ago

Indicates that the -Time should be subtracted from the current time.

Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FluentAgo
Position: Named
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Because

The reason why the actual value should be before the expected value.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Expected

The expected [datetime] value.

Type: System.DateTime
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Expected
Position: 0
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-FromNow

Indicates that the -Time should be added to the current time.

Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FluentFromNow
Position: Named
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Now

Indicates that the current time should be used as the expected time.

Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: Now
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Time

The time to add or subtract from the current time. This parameter uses fluent time syntax e.g. 1minute.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: FluentFromNow
Position: 0
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
- Name: FluentAgo
Position: 0
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

System.Object

OUTPUTS

NOTES

The Should-BeBefore assertion is the opposite of the Should-BeAfter assertion.

Use the -ErrorAction parameter to control soft-assertion behavior for this assertion. -ErrorAction Continue records the failure and lets the rest of the test run (a soft assertion), while -ErrorAction Stop fails the test immediately, for example to guard a precondition before continuing.

When -ErrorAction is not specified, the behavior comes from Should.ErrorAction in the configuration, which defaults to Stop. See https://pester.dev/docs/assertions/soft-assertions for more about soft assertions.

VERSION

This page was generated using comment-based help in Pester 6.0.0.