add test for util.assert

This commit is contained in:
David Lechner
2020-05-27 20:57:22 -05:00
committed by David Lechner
parent 59c14a3ad7
commit 9d789c13e1
2 changed files with 9 additions and 2 deletions
+9 -1
View File
@@ -1,7 +1,15 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2020 The Pybricks Authors
import { hex } from '.';
import { assert, hex } from '.';
test('assert', () => {
const assertTrue = jest.fn(() => assert(true, 'should not throw'));
assertTrue();
expect(assertTrue).toHaveReturned();
expect(() => assert(false, 'should throw')).toThrow();
});
test('hex', () => {
expect(hex(0, 2)).toBe('0x00');
-1
View File
@@ -8,7 +8,6 @@
* @param message Informational message for debugging
*/
export function assert(condition: boolean, message: string): void {
/* istanbul ignore next */
if (!condition) {
throw Error(message);
}