Files
common/packages/util/src/assert.spec.ts
T
2021-11-19 13:37:43 +02:00

39 lines
1.1 KiB
TypeScript

// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { assert, assertReturn } from '.';
describe('assert', (): void => {
it('should not throw an error when test is true', (): void => {
assert(true, 'nothing should be thrown');
});
it('should throw an error when test is not true', (): void => {
expect(
() => assert(false, 'error thrown')
).toThrow(/error thrown/);
});
it('should throw an error when message: () => string', (): void => {
expect(
() => assert(false, (): string => 'message from function')
).toThrow(/message from function/);
});
});
describe('assertReturn', (): void => {
it('should not throw an error when result is true', (): void => {
expect(assertReturn(true, 'nothing should be thrown')).toEqual(true);
});
it('should not throw an error when result is false', (): void => {
expect(assertReturn(false, 'nothing should be thrown')).toEqual(false);
});
it('should throw an error when result is undefined', (): void => {
expect(
() => assertReturn(undefined, 'something thrown')
).toThrow(/something thrown/);
});
});