new test for invariant
This commit is contained in:
parent
4a8647b452
commit
46a2d3c7d2
|
@ -37,6 +37,7 @@
|
|||
"email": "issues@astro-ghostcms.xyz"
|
||||
},
|
||||
"main": "index.ts",
|
||||
"types": "types.ts",
|
||||
"files": [
|
||||
"src",
|
||||
".env.demo",
|
||||
|
@ -48,7 +49,7 @@
|
|||
"exports": {
|
||||
".": "./index.ts",
|
||||
"./api": "./src/api/index.ts",
|
||||
"./api-core": "./src/api/content-api",
|
||||
"./api-core": "./src/api/content-api/index.ts",
|
||||
"./404.astro": "./src/default-routes/404/404.astro",
|
||||
"./rss.xml.ts": "./src/default-routes/rss.xml.ts",
|
||||
"./config": "./src/integrations/virtual-config.ts",
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
|
||||
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),
|
||||
) {
|
||||
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;
|
||||
}
|
||||
|
||||
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"))
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue