feat: add unit tests
This commit is contained in:
parent
9e58978b4d
commit
7cbb07fd67
7 changed files with 1734 additions and 11 deletions
7
apps/main/jest.config.js
Normal file
7
apps/main/jest.config.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||
export default {
|
||||
verbose: true,
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
testPathIgnorePatterns: ["e2e"], // ignore playwright tests
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
"dev": "vite dev",
|
||||
"build": "pnpm cp && vite build",
|
||||
"serve": "serve build --listen 5173",
|
||||
"test:unit": "jest",
|
||||
"test:e2e": "playwright test",
|
||||
"clean": "rm -rf .turbo .svelte-kit build node_modules vite.config.ts.timestamp-*",
|
||||
"lint": "eslint ."
|
||||
|
@ -23,6 +24,7 @@
|
|||
"@playwright/test": "^1.36.2",
|
||||
"@sveltejs/adapter-static": "^2.0.2",
|
||||
"@sveltejs/kit": "^1.22.1",
|
||||
"@types/jest": "^29.5.3",
|
||||
"@typescript-eslint/eslint-plugin": "^5.61.0",
|
||||
"@typescript-eslint/parser": "^5.61.0",
|
||||
"autoprefixer": "^10.4.14",
|
||||
|
@ -31,6 +33,7 @@
|
|||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||
"eslint-plugin-svelte": "^2.32.2",
|
||||
"jest": "^29.6.2",
|
||||
"postcss": "^8.4.25",
|
||||
"prettier-plugin-svelte": "^2.10.1",
|
||||
"prettier-plugin-tailwindcss": "^0.3.0",
|
||||
|
@ -39,6 +42,7 @@
|
|||
"svelte": "^4.0.5",
|
||||
"svelte-check": "^3.4.5",
|
||||
"tailwindcss": "^3.3.2",
|
||||
"ts-jest": "^29.1.1",
|
||||
"tslib": "^2.6.0",
|
||||
"typescript": "^5.1.6",
|
||||
"vite": "^4.4.2"
|
||||
|
|
85
apps/main/src/utils/getAge.test.ts
Normal file
85
apps/main/src/utils/getAge.test.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import { testing } from "./getAge"
|
||||
|
||||
const { birth, dateFormatOption, getAge, ageInt, ageDecimal, isOverBirthDay } =
|
||||
testing
|
||||
|
||||
describe("getAge tests", () => {
|
||||
test("birthday should be 2002-07-30", () => {
|
||||
expect(birth).toEqual(new Date("2002-07-30, 00:00:00.000 +09:00"))
|
||||
})
|
||||
|
||||
test("isOverBirthDay to work", () => {
|
||||
expect(
|
||||
isOverBirthDay(new Date("2022-12-31, 00:00:00.000 +09:00"))
|
||||
).toEqual(true)
|
||||
|
||||
expect(
|
||||
isOverBirthDay(new Date("2023-01-01, 00:00:00.000 +09:00"))
|
||||
).toEqual(false)
|
||||
|
||||
//
|
||||
|
||||
expect(
|
||||
isOverBirthDay(new Date("2023-07-29, 00:00:00.000 +09:00"))
|
||||
).toEqual(false)
|
||||
|
||||
expect(
|
||||
isOverBirthDay(new Date("2023-07-30, 00:00:00.000 +09:00"))
|
||||
).toEqual(true)
|
||||
|
||||
expect(
|
||||
isOverBirthDay(new Date("2023-07-31, 00:00:00.000 +09:00"))
|
||||
).toEqual(true)
|
||||
|
||||
//
|
||||
|
||||
expect(
|
||||
isOverBirthDay(new Date("2023-12-31, 00:00:00.000 +09:00"))
|
||||
).toEqual(true)
|
||||
|
||||
expect(
|
||||
isOverBirthDay(new Date("2024-01-01, 00:00:00.000 +09:00"))
|
||||
).toEqual(false)
|
||||
})
|
||||
|
||||
test("dateFormatOption should work properly", () => {
|
||||
expect(
|
||||
new Date("2002-07-30, 00:00:00.000 +09:00").toLocaleString(
|
||||
"en-US",
|
||||
dateFormatOption
|
||||
)
|
||||
).toEqual("7/30/2002, 00:00:00.000 GMT+09:00")
|
||||
})
|
||||
|
||||
test("ageInt to work", () => {
|
||||
expect(ageInt(birth)).toEqual(0)
|
||||
expect(ageInt(new Date("2023-07-29"))).toEqual(20)
|
||||
expect(ageInt(new Date("2023-07-30"))).toEqual(21)
|
||||
expect(ageInt(new Date("2023-07-31"))).toEqual(21)
|
||||
})
|
||||
|
||||
test("ageDecimal to work", () => {
|
||||
expect(ageDecimal(new Date("2023-07-29, 00:00:00.000 +09:00"))).toEqual(
|
||||
0.9972602739726028
|
||||
)
|
||||
expect(ageDecimal(new Date("2023-07-30, 00:00:00.000 +09:00"))).toEqual(
|
||||
0
|
||||
)
|
||||
expect(ageDecimal(new Date("2023-07-31, 00:00:00.000 +09:00"))).toEqual(
|
||||
0.00273224043715847
|
||||
)
|
||||
})
|
||||
|
||||
test("getAge to work", () => {
|
||||
expect(getAge(new Date("2002-07-30, 00:00:00.000 +09:00"))).toEqual(0.0)
|
||||
expect(getAge(new Date("2023-07-29, 00:00:00.000 +09:00"))).toEqual(
|
||||
20.997260273972604
|
||||
)
|
||||
expect(getAge(new Date("2023-07-30, 00:00:00.000 +09:00"))).toEqual(
|
||||
21.0
|
||||
)
|
||||
expect(getAge(new Date("2023-07-31, 00:00:00.000 +09:00"))).toEqual(
|
||||
21.002732240437158
|
||||
)
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue