Curve conversion tests (#1214)
This commit is contained in:
@@ -10,13 +10,13 @@ describe('assert', (): void => {
|
||||
|
||||
it('should throw an error when test is not true', (): void => {
|
||||
expect(
|
||||
(): void => assert(false, 'error thrown')
|
||||
() => assert(false, 'error thrown')
|
||||
).toThrow(/error thrown/);
|
||||
});
|
||||
|
||||
it('should throw an error when message: () => string', (): void => {
|
||||
expect(
|
||||
(): void => assert(false, (): string => 'message from function')
|
||||
() => assert(false, (): string => 'message from function')
|
||||
).toThrow(/message from function/);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isFunction } from './is/function';
|
||||
import { isNull } from './is/null';
|
||||
import { isUndefined } from './is/undefined';
|
||||
|
||||
type MessageFn = () => string;
|
||||
@@ -36,8 +37,8 @@ export function assert (condition: unknown, message: string | MessageFn): assert
|
||||
* @name assertReturn
|
||||
* @summart Returns when the value is not undefined, otherwise throws assertion error
|
||||
*/
|
||||
export function assertReturn <T> (value: T | undefined, message: string | MessageFn): T {
|
||||
assert(!isUndefined(value), message);
|
||||
export function assertReturn <T> (value: T | undefined | null, message: string | MessageFn): T {
|
||||
assert(!isUndefined(value) && !isNull(value), message);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user