added tests
This commit is contained in:
26
frontend/src/lib/assert.test.ts
Normal file
26
frontend/src/lib/assert.test.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { assert } from './assert';
|
||||
|
||||
describe('assert', () => {
|
||||
test('does not throw for true condition', () => {
|
||||
expect(() => assert(true, 'should not throw')).not.toThrow();
|
||||
});
|
||||
|
||||
test('throws in dev mode for false condition', () => {
|
||||
expect(() => assert(false, 'should throw')).toThrow('Assertion failed: should throw');
|
||||
});
|
||||
|
||||
test('includes message in error', () => {
|
||||
try {
|
||||
assert(false, 'custom message here');
|
||||
} catch (e: any) {
|
||||
expect(e.message).toContain('custom message here');
|
||||
}
|
||||
});
|
||||
|
||||
test('does not throw for truthy values', () => {
|
||||
expect(() => assert(1 === 1, 'math works')).not.toThrow();
|
||||
expect(() => assert('hello' === 'hello', 'strings work')).not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user