mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -04:00
test(rewrite): Tests using TS-Jest for common package, fix isNotBlank
This commit is contained in:
parent
5a899ac0a5
commit
de9f5c1c06
@ -11,6 +11,7 @@
|
||||
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
|
||||
"build:types": "tsc --emitDeclarationOnly --declaration --outDir dist/types",
|
||||
"build": "run-p build:esm build:cjs build:types",
|
||||
"test": "jest .",
|
||||
"cleanbuild": "run-s clean build"
|
||||
},
|
||||
"exports": {
|
||||
|
@ -20,7 +20,7 @@ export function isNotBlank(value: string | null | undefined): boolean {
|
||||
if (value.length < 1) {
|
||||
return false;
|
||||
}
|
||||
return value.trim().length > 1;
|
||||
return value.trim().length > 0;
|
||||
}
|
||||
export const isBlank = not(isNotBlank);
|
||||
|
||||
|
10
new/common/test/tsconfig.json
Normal file
10
new/common/test/tsconfig.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "..",
|
||||
"paths": {
|
||||
"#self/*": ["src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["./**/*.ts"]
|
||||
}
|
33
new/common/test/util.ts
Normal file
33
new/common/test/util.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { isNotBlank, isNotNull } from "#self/util";
|
||||
describe("isNotNull", () => {
|
||||
it("should return true for non-null values", () => {
|
||||
for (const value of [0, "0", "", "hello!", NaN, "1", " "]) {
|
||||
expect(isNotNull(value)).toBeTruthy();
|
||||
}
|
||||
});
|
||||
it("should return false for null values", () => {
|
||||
for (const value of [null, undefined]) {
|
||||
expect(isNotNull(value)).toBeFalsy();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("isNotBlank", () => {
|
||||
it("should return true for non-blank strings", () => {
|
||||
for (const value of [
|
||||
"abababa",
|
||||
"this is not empty",
|
||||
"...",
|
||||
".",
|
||||
"0",
|
||||
"1",
|
||||
]) {
|
||||
expect(isNotBlank(value)).toBeTruthy();
|
||||
}
|
||||
});
|
||||
it("should return false for blank strings", () => {
|
||||
for (const value of [" ", " ", "\n", "\n\n", "\r", "\t"]) {
|
||||
expect(isNotBlank(value)).toBeFalsy();
|
||||
}
|
||||
});
|
||||
});
|
@ -4,11 +4,14 @@
|
||||
"format": "prettier -w ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.5",
|
||||
"@typescript-eslint/eslint-plugin": "^6.4.1",
|
||||
"@typescript-eslint/parser": "^6.4.1",
|
||||
"eslint": "^8.48.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.0.2",
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
1884
new/pnpm-lock.yaml
generated
1884
new/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user