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