Files
common/packages/util/src/assert.spec.ts
T
2019-09-10 17:44:47 +02:00

26 lines
780 B
TypeScript

// Copyright 2017-2019 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { assert } from '.';
describe('assert', (): void => {
it('should not throw an error when test is true', (): void => {
expect(
assert(true, 'nothing should be thrown')
).toEqual(true);
});
it('should throw an error when test is not true', (): void => {
expect(
(): boolean => assert(false, 'error thrown')
).toThrow(/error thrown/);
});
it('should throw an error when message: () => string', (): void => {
expect(
(): boolean => assert(false, (): string => 'message from function')
).toThrow(/message from function/);
});
});