Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertions return boolean #2586

Closed
wants to merge 10 commits into from
162 changes: 119 additions & 43 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,68 @@ export type SnapshotOptions = {
};

export interface Assertions {
/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */
/**
* Assert that `actual` is
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
* returning Boolean indicating whether the assertion passes. Comes with
* power-assert.
*/
assert: AssertAssertion;

/** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
/**
* Assert that `actual` is [deeply
* equal](https://github.com/concordancejs/concordance#comparison-details) to
* `expected`, returning Boolean indicating whether the assertion passes.
*/
deepEqual: DeepEqualAssertion;

/** Assert that `actual` is like `expected`. */
/**
* Assert that `value` is like `selector`, returning Boolean indicating
* whether the assertion passes.
*/
like: LikeAssertion;

/** Fail the test. */
/** Fail the test, always returning `false`. */
fail: FailAssertion;

/** Assert that `actual` is strictly false. */
/**
* Assert that `actual` is strictly false, returning Boolean indicating
* whether the assertion passes.
*/
false: FalseAssertion;

/** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
/**
* Assert that `actual` is
* [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning
* Boolean whether the assertion passes.
*/
falsy: FalsyAssertion;

/**
* Assert that `actual` is [the same
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
* as `expected`, returning Boolean indicating whether the assertion passes.
*/
is: IsAssertion;

/**
* Assert that `actual` is not [the same
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
* as `expected`, returning Boolean indicating whether the assertion passes.
*/
not: NotAssertion;

/** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
/**
* Assert that `actual` is not [deeply
* equal](https://github.com/concordancejs/concordance#comparison-details) to
* `expected`, returning Boolean indicating whether the assertion passes.
*/
notDeepEqual: NotDeepEqualAssertion;

/** Assert that `string` does not match the regular expression. */
/**
* Assert that `string` does not match the regular expression, returning
* Boolean indicating whether the assertion passes.
*/
notRegex: NotRegexAssertion;

/** Assert that the function does not throw. */
Expand All @@ -81,10 +109,13 @@ export interface Assertions {
/** Assert that the async function does not throw, or that the promise does not reject. Must be awaited. */
notThrowsAsync: NotThrowsAsyncAssertion;

/** Count a passing assertion. */
/** Count a passing assertion, always returning `true`. */
pass: PassAssertion;

/** Assert that `string` matches the regular expression. */
/**
* Assert that `string` matches the regular expression, returning Boolean
* indicating whether the assertion passes.
*/
regex: RegexAssertion;

/**
Expand All @@ -105,56 +136,82 @@ export interface Assertions {
*/
throwsAsync: ThrowsAsyncAssertion;

/** Assert that `actual` is strictly true. */
/**
* Assert that `actual` is strictly true, returning Boolean indicating
* whether the assertion passes.
*/
true: TrueAssertion;

/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
/**
* Assert that `actual` is
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
* returning Boolean indicating whether the assertion passes.
*/
truthy: TruthyAssertion;
}

export interface AssertAssertion {
/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Comes with power-assert. */
(actual: any, message?: string): void;
/**
* Assert that `actual` is
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
* returning Boolean indicating whether the assertion passes. Comes with
* power-assert.
*/
(actual: any, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, message?: string): void;
}

export interface DeepEqualAssertion {
/** Assert that `actual` is [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
/**
* Assert that `actual` is [deeply
* equal](https://github.com/concordancejs/concordance#comparison-details) to
* `expected`, returning Boolean indicating whether the assertion passes.
*/
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
}

export interface LikeAssertion {
/** Assert that `value` is like `selector`. */
(value: any, selector: Record<string, any>, message?: string): void;
/**
* Assert that `value` is like `selector`, returning Boolean indicating
* whether the assertion passes.
*/
(value: any, selector: Record<string, any>, message?: string): boolean;

/** Skip this assertion. */
skip(value: any, selector: any, message?: string): void;
}

export interface FailAssertion {
/** Fail the test. */
(message?: string): void;
/** Fail the test, always returning `false`. */
(message?: string): false;

/** Skip this assertion. */
skip(message?: string): void;
}

export interface FalseAssertion {
/** Assert that `actual` is strictly false. */
(actual: any, message?: string): void;
/**
* Assert that `actual` is strictly false, returning Boolean indicating
* whether the assertion passes.
*/
(actual: any, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, message?: string): void;
}

export interface FalsyAssertion {
/** Assert that `actual` is [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy). */
(actual: any, message?: string): void;
/**
* Assert that `actual` is
* [falsy](https://developer.mozilla.org/en-US/docs/Glossary/Falsy), returning
* Boolean whether the assertion passes.
*/
(actual: any, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, message?: string): void;
Expand All @@ -163,9 +220,10 @@ export interface FalsyAssertion {
export interface IsAssertion {
/**
* Assert that `actual` is [the same
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
* as `expected`, returning Boolean indicating whether the assertion passes.
*/
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
Expand All @@ -174,25 +232,33 @@ export interface IsAssertion {
export interface NotAssertion {
/**
* Assert that `actual` is not [the same
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) as `expected`.
* value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)
* as `expected`, returning Boolean indicating whether the assertion passes.
*/
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
}

export interface NotDeepEqualAssertion {
/** Assert that `actual` is not [deeply equal](https://github.com/concordancejs/concordance#comparison-details) to `expected`. */
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): void;
/**
* Assert that `actual` is not [deeply
* equal](https://github.com/concordancejs/concordance#comparison-details) to
* `expected`, returning Boolean indicating whether the assertion passes.
*/
<ValueType = any>(actual: ValueType, expected: ValueType, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, expected: any, message?: string): void;
}

export interface NotRegexAssertion {
/** Assert that `string` does not match the regular expression. */
(string: string, regex: RegExp, message?: string): void;
/**
* Assert that `string` does not match the regular expression, returning
* Boolean indicating whether the assertion passes.
*/
(string: string, regex: RegExp, message?: string): boolean;

/** Skip this assertion. */
skip(string: string, regex: RegExp, message?: string): void;
Expand All @@ -218,16 +284,19 @@ export interface NotThrowsAsyncAssertion {
}

export interface PassAssertion {
/** Count a passing assertion. */
(message?: string): void;
/** Count a passing assertion, always returning `true`. */
(message?: string): true;

/** Skip this assertion. */
skip(message?: string): void;
}

export interface RegexAssertion {
/** Assert that `string` matches the regular expression. */
(string: string, regex: RegExp, message?: string): void;
/**
* Assert that `string` matches the regular expression, returning Boolean
* indicating whether the assertion passes.
*/
(string: string, regex: RegExp, message?: string): boolean;

/** Skip this assertion. */
skip(string: string, regex: RegExp, message?: string): void;
Expand Down Expand Up @@ -296,16 +365,23 @@ export interface ThrowsAsyncAssertion {
}

export interface TrueAssertion {
/** Assert that `actual` is strictly true. */
(actual: any, message?: string): void;
/**
* Assert that `actual` is strictly true, returning Boolean indicating
* whether the assertion passes.
*/
(actual: any, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, message?: string): void;
}

export interface TruthyAssertion {
/** Assert that `actual` is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). */
(actual: any, message?: string): void;
/**
* Assert that `actual` is
* [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy),
* returning Boolean indicating whether the assertion passes.
*/
(actual: any, message?: string): boolean;

/** Skip this assertion. */
skip(actual: any, message?: string): void;
Expand Down Expand Up @@ -433,7 +509,7 @@ export interface CbExecutionContext<Context = unknown> extends ExecutionContext<
end(error?: any): void;
}

export type ImplementationResult = PromiseLike<void> | Subscribable | void;
export type ImplementationResult = PromiseLike<void> | Subscribable | boolean | void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't change. It's the return type of the function you pass to test().

export type Implementation<Context = unknown> = (t: ExecutionContext<Context>) => ImplementationResult;
export type CbImplementation<Context = unknown> = (t: CbExecutionContext<Context>) => ImplementationResult;

Expand Down
Loading