done with tests for now

This commit is contained in:
Adam Matthiesen 2024-01-26 07:24:24 -08:00
parent 46a2d3c7d2
commit 90826e29cb
1 changed files with 17 additions and 19 deletions

View File

@ -1,36 +1,34 @@
import { describe, expect, it } from "vitest";
// Modified version of invariant script to allow tests
const isProduction= false;
const prefix: string = 'Invariant failed';
const testTrue = true;
const testFalse = false;
function invariant(
// biome-ignore lint/suspicious/noExplicitAny: we know what we are doing
condition: any,
message?: string | (() => string),
) {
function invariant( // biome-ignore lint/suspicious/noExplicitAny: we know what we are doing
condition: any, message?: string | (() => string), ) {
if (condition) {
return;
}
if (isProduction) {
throw new Error(prefix);
}
const provided: string | undefined = typeof message === 'function' ? message() : message;
const value: string = provided ? `${prefix}: ${provided}` : prefix;
return value;
}
// TEST SECTION
const testTrue = true;
const testFalse = false;
describe('test invariant', () => {
it('Test `true` value', () => {
invariant(testTrue, "This should not error")
expect(null)
})
it('Test `false` value', () => {
invariant(testFalse, "This should Error")
expect(String("Invariant failed"))
})
it('Test `true` value', () => {
invariant(testTrue, "This should not error")
expect(null)
})
it('Test `false` value', () => {
invariant(testFalse, "This should Error")
expect(String("Invariant failed"))
})
})