test(rewrite): Tests using TS-Jest for common package, fix isNotBlank

This commit is contained in:
tecc 2023-09-19 23:09:46 +02:00
parent 5a899ac0a5
commit de9f5c1c06
No known key found for this signature in database
GPG Key ID: 622EEC5BAE5EBD3A
6 changed files with 1932 additions and 1 deletions

View File

@ -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": {

View File

@ -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);

View File

@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": "..",
"paths": {
"#self/*": ["src/*"]
}
},
"include": ["./**/*.ts"]
}

33
new/common/test/util.ts Normal file
View 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();
}
});
});

View File

@ -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

File diff suppressed because it is too large Load Diff