-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { assert, assertCondition, fatal } from './assert' | ||
|
||
describe('assert.ts', () => { | ||
describe('fatal', () => { | ||
it('should throw an error with the correct message', () => { | ||
expect(() => fatal('test message')).toThrow('test message') | ||
}) | ||
}) | ||
|
||
describe('assert', () => { | ||
it('should throw an error when the condition is falsy', () => { | ||
expect(() => assert(false, 'condition is false')).toThrow('condition is false') | ||
expect(() => assert(null, 'condition is null')).toThrow('condition is null') | ||
expect(() => assert(Number.NaN, 'condition is NaN')).toThrow('condition is NaN') | ||
}) | ||
|
||
it('should not throw an error when the condition is truthy', () => { | ||
expect(() => assert(true, 'condition is true')).not.toThrow() | ||
expect(() => assert(1, 'condition is 1')).not.toThrow() | ||
expect(() => assert('non-empty string', 'condition is non-empty string')).not.toThrow() | ||
}) | ||
}) | ||
|
||
describe('assertCondition', () => { | ||
it('should behave the same as assert', () => { | ||
expect(() => assertCondition(false, 'condition is false')).toThrow('condition is false') | ||
expect(() => assertCondition(true, 'condition is true')).not.toThrow() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters