Skip to content

Commit e0a5948

Browse files
docs: classes docstrings (#44)
* docs: add docstrings to classes * Address @JoseLion feedback * Add docstrings to TypeFactories.ts * Add typeParam tags Co-authored-by: Christian <[email protected]>
1 parent 178fe09 commit e0a5948

12 files changed

+131
-3
lines changed

src/lib/ArrayAssertion.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { UnsupportedOperationError } from "./errors/UnsupportedOperationError";
66
import { expect } from "./expect";
77
import { TypeFactory } from "./helpers/TypeFactories";
88

9+
/**
10+
* Encapsulates assertion methods applicable to arrays.
11+
*
12+
* @param T the type of the array
13+
*/
914
export class ArrayAssertion<T> extends Assertion<T[]> {
1015

1116
public constructor(actual: T[]) {
@@ -270,6 +275,8 @@ export class ArrayAssertion<T> extends Assertion<T[]> {
270275
* .toBePositive();
271276
* ```
272277
*
278+
* @typeParam S the type of the factory's value
279+
* @typeParam A the type of the assertion factory
273280
* @param index the index of the array to extract the value
274281
* @param typeFactory a factory to assert the extracted value type and create
275282
* an assertion for it

src/lib/Assertion.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export interface ExecuteOptions {
2222
invertedError: AssertionError;
2323
}
2424

25+
/**
26+
* Base class for all assertions.
27+
*
28+
* @param T the type of the `actual` value
29+
*/
2530
export class Assertion<T> {
2631

2732
protected readonly actual: T;
@@ -329,6 +334,8 @@ export class Assertion<T> {
329334
* .isValid();
330335
* ```
331336
*
337+
* @typeParam S the type of the factory's value
338+
* @typeParam A the type of the assertion factory
332339
* @param typeFactory a factory to assert the type and create an assertion
333340
* @returns a more specific assertion based on the factory type
334341
*/

src/lib/BooleanAssertion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { AssertionError } from "assert";
22

33
import { Assertion } from "./Assertion";
44

5+
/**
6+
* Encapsulates assertion methods applicable to values of type boolean
7+
*/
58
export class BooleanAssertion extends Assertion<boolean> {
69

710
constructor(actual: boolean) {

src/lib/DateAssertion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ const DATE_METHOD_MAP: Record<keyof DateOptions, DateMethod> = {
1414
year: "getFullYear"
1515
};
1616

17+
/**
18+
* Encapsulates assertion methods applicable to values of type Date
19+
*/
1720
export class DateAssertion extends Assertion<Date> {
1821

1922
constructor(actual: Date) {

src/lib/ErrorAssertion.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { AssertionError } from "assert";
22

33
import { Assertion } from "./Assertion";
44

5+
/**
6+
* Encapsulates assertion methods applicable to Error instances.
7+
*
8+
* @param T the Error constructor type
9+
*/
510
export class ErrorAssertion<T extends Error> extends Assertion<T> {
611

712
public constructor(actual: T) {

src/lib/FunctionAssertion.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export interface Class<T> extends Function {
1212

1313
const NoThrow = Symbol("NoThrow");
1414

15+
/**
16+
* Encapsulates assertion methods applicable to functions.
17+
*
18+
* @param T the type of the function's signature
19+
*/
1520
export class FunctionAssertion<T extends AnyFunction> extends Assertion<T> {
1621

1722
constructor(actual: T) {
@@ -65,8 +70,9 @@ export class FunctionAssertion<T extends AnyFunction> extends Assertion<T> {
6570
* .toHaveMessage("Something failed!");
6671
* ```
6772
*
68-
* @param ErrorType optional error type constructor to check the thrown error
69-
* against. If is not provided, it defaults to `Error`
73+
* @typeParam E the type of the `Error`
74+
* @param ExpectedType optional error type constructor to check the thrown error
75+
* against. If is not provided, it defaults to {@link Error}
7076
* @returns a new {@link ErrorAssertion} to assert over the error
7177
*/
7278
public toThrowError(): ErrorAssertion<Error>;
@@ -117,6 +123,8 @@ export class FunctionAssertion<T extends AnyFunction> extends Assertion<T> {
117123
* .toBeNegative();
118124
* ```
119125
*
126+
* @typeParam S the type of the factory's value
127+
* @typeParam A the type of the assertion factory
120128
* @param expected the value the function is expected to throw
121129
* @param typeFactory optional type factory to perform more specific
122130
* assertions over the thrown value

src/lib/NumberAssertion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export type BetweenOptions =
3030
| LowInclusiveBetweenOptions
3131
| HighInclusiveBetweenOptions;
3232

33+
/**
34+
* Encapsulates assertion methods applicable to values of type number
35+
*/
3336
export class NumberAssertion extends Assertion<number> {
3437

3538
constructor(actual: number) {

src/lib/ObjectAssertion.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export type Entry<T, K = keyof T> = K extends keyof T
99
? [K, T[K]]
1010
: never;
1111

12+
/**
13+
* Encapsulates assertion methods applicable to objects.
14+
*
15+
* @param T the object's definition type
16+
*/
1217
export class ObjectAssertion<T extends JSObject> extends Assertion<T> {
1318

1419
constructor(actual: T) {

src/lib/PromiseAssertion.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { isDeepStrictEqual } from "util";
33

44
import { Assertion } from "./Assertion";
55

6+
/**
7+
* Encapsulates assertion methods applicable to Promises
8+
*
9+
* @param T the type of the value of the promise
10+
* @param I type to track the current inverted state
11+
*/
612
export class PromiseAssertion<T, I extends boolean = false> extends Assertion<Promise<T>> {
713

814
// @ts-ignore:
@@ -139,6 +145,7 @@ export class PromiseAssertion<T, I extends boolean = false> extends Assertion<Pr
139145
* **Important:** Remember to return or `await` for this assertion to not leave
140146
* the promise asynchronous to the test
141147
*
148+
* @typeParam E the type of the rejected value
142149
* @param expected the expected error to be rejected by the promise
143150
* @returns a promise with the caught error
144151
*/

src/lib/StringAssertion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { AssertionError } from "assert";
22

33
import { Assertion } from "./Assertion";
44

5+
/**
6+
* Encapsulates assertion methods applicable to values of type string
7+
*/
58
export class StringAssertion extends Assertion<string> {
69

710
constructor(actual: string) {

0 commit comments

Comments
 (0)