DateToCheck
The DateToCheck class provides a way to verify if a date is valid or how it compares to a compare date (before, equal, after). It allows for positive and negative checks. This class extends the Question<boolean> class. DateToCheck does not rely on any specific Ability.
Extends
This class extends the abstract Question<boolean> class from Core.
Methods
answeredBy
public async answeredBy(actor: Actor): Promise<boolean>;
- Description: Perform the verification based on the specified action.
- Parameters:
actor- The actor performing the action.
- Returns:
Promise<boolean>- The verification result (true or false).
whichIs
Introduced in: 1.0.0
static get whichIs(date: Date): DateToCheck;
- Description: Create a new instance of the
DateToCheckclass for positive verification. - Parameters:
date- The date to verify
- Returns:
DateToCheck- A new instance of theDateToCheckclass.
Usage:
await actor.asks(
DateToCheck.whichIs(myDate).is.valid,
);
is (public/static)
Introduced in: 1.0.0
public get is(): DateToCheck;
// and
static get is(): DateToCheck;
- Description:
- public: Sets the verification mode to positive
- static: Create a new instance of the
DateToCheckclass for positive verification.
- Returns:
DateToCheck- A new instance of theDateToCheckclass.
Usage:
await actor.asks(
// public function
DateToCheck.whichIs(myDate).is.valid,
// or static function - date defaults to now
DateToCheck.is.valid,
);
isNot (public/static)
Introduced in: 1.0.0
public get isNot(): DateToCheck;
// and
static get isNot(): DateToCheck;
- Description:
- public: Sets the verification mode to negative
- static: Create a new instance of the
DateToCheckclass for negative verification.
- Returns:
DateToCheck- A new instance of theDateToCheckclass.
Usage:
await actor.asks(
// public function
DateToCheck.whichIs(myDate).isNot.valid,
// or static function - date defaults to now
// this specific example will never come true because the default for date will always be a valid date
DateToCheck.isNot.valid,
);
valid
Introduced in: 1.0.0
public valid(): DateToCheck;
- Description: Set up the verification for vdate validity.
- Returns:
DateToCheck- The updated instance of theDateToCheckclass.
Usage:
// To verify that the date is valid
await actor.asks(
DateToCheck.whichIs(myDate).is.valid,
);
// To verify that the date is not valid
await actor.asks(
DateToCheck.whichIs(myDate).isNot.valid,
);
after
Introduced in: 1.0.0
public after(compareDate?: Date): DateToCheck;
- Description: Set up the verification for the date to be after a compare date.
- Parameters:
compareDate- The date to compare against (optional - defaults to now)
- Returns:
DateToCheck- The updated instance of theDateToCheckclass.
Usage:
// To verify that the date is after compare date
await actor.asks(
DateToCheck.whichIs(myDate).is.after(compareDate),
);
// To verify that the date is not after compare date
await actor.asks(
DateToCheck.whichIs(myDate).isNot.after(compareDate),
);
before
Introduced in: 1.0.0
public before(compareDate?: Date): DateToCheck;
- Description: Set up the verification for the date to be before a compare date.
- Parameters:
compareDate- The date to compare against (optional - defaults to now)
- Returns:
DateToCheck- The updated instance of theDateToCheckclass.
Usage:
// To verify that the date is before compare date
await actor.asks(
DateToCheck.whichIs(myDate).is.before(compareDate),
);
// To verify that the date is not before compare date
await actor.asks(
DateToCheck.whichIs(myDate).isNot.before(compareDate),
);
equalTo
Introduced in: 1.0.0
public equalTo(compareDate?: Date): DateToCheck;
- Description: Set up the verification for the date to be equal to a compare date.
- Parameters:
compareDate- The date to compare against (optional - defaults to now)
- Returns:
DateToCheck- The updated instance of theDateToCheckclass.
Usage:
// To verify that the date is equal to compare date
await actor.asks(
DateToCheck.whichIs(myDate).is.equalTo(compareDate),
);
// To verify that the date is not equal to compare date
await actor.asks(
DateToCheck.whichIs(myDate).isNot.equalTo(compareDate),
);
Methods inherited from Core Question
failAsFalse
Introduced in core: 0.5.0
In some cases you may want to ask questions to find out about the status of the system under test to make decisions on how to move on with your test. In order to not fail a test but receive information about questions being answered negative you can use failAsFalse on a question which then returns a boolean value instead.
public get failAsFalse(): Question;
- Description: Returns false instead of failing when exception occurrs.
- Returns:
Question- Returns the current question.
Usage:
// get evaluation result based on valid check
const evaluationResult = await actor.asks(
MyQuestion.is.asExpected().failAsFalse,
);
// proceed based on answer from above
if (wasLoggedIn === false) {
// some code to be executed on false case
}
withAbilityAlias
Introduced in core: 0.3.0
It happens that there is the need to make use of the same ability but with different settings.
The solution Testla Screenplay offers is Ability Aliasing. With that multiple instances of an ability can be assigned to a user at the same time.
To use an aliased ability in a question you can use the withAbilityAlias method to define the alias to be used during execution.
public withAbilityAlias(alias: string): Question;
- Description: Defines the ability alias to be used during execution.
- Parameters:
alias- The alias.
- Returns:
Question- Returns the current question.
Usage:
await actor.asks(
MyQuestion.is.asExpected().withAbilityAlias('myAlias'),
);