expect() function
Perform assertions/checks on the state of a value.
Signature:
declare function expect<T>(value: T, customMessage?: string): Assertion<T>;
Parameters
Parameter | Type | Description |
|---|---|---|
value | T | The "actual" value to perform checks against. |
customMessage | string | (Optional) A custom message to use if the check fails; replaces whatever message expect throws. |
Returns:
Assertion<T>
An instance of Assertion that you should chain for checks.
Remarks
The value you provide is reffered to as the "actual" value.
You can then use the instance returned by expect to make various "assertions" about the state of the value. expect will throw a descriptive error message if any of the checks fail.
For a full list of available checks, take a look at the API.
Example 1
expect(5).to.equal(5);
expect("Daymon").to.have.the.substring("Day");
expect([1,2,3]).to.include(1).but.not.include(4);
expect(Sport.Basketball).to.be.the.enum(Sport).and.to.be.oneOf(["Basketball", "Soccer"]);
Example 2
Using a custom message
expect(player.money, "You don't have enough money").to.be.gte(pet.cost);