Create Unit Test on Nuxt with vitest

Sample Code for Test - useCommonUtil.ts export default () => { const isItemInListByType = ( list: T[] | undefined, key: keyof T, value: T ): boolean => { if (!list || list.length === 0) { console.error("List is empty or undefined."); return false; } const itemIndex = list.findIndex((item) => item === value); if (itemIndex === -1) { console.error(`Item with ${String(key)}=${value} not found in the list.`); return false; } return…

naiwaen.debuggingsoft.com/2025…


Create Unit Test on Nuxt with vitest


Sample Code for Test - useCommonUtil.ts
export default () => { const isItemInListByType = <T>( list: T[] | undefined, key: keyof T, value: T ): boolean => { if (!list || list.length === 0) { console.error("List is empty or undefined."); return false; } const itemIndex = list.findIndex((item) => item[key] === value[key]); if (itemIndex === -1) { console.error(`Item with ${String(key)}=${value} not found in the list.`); return false; } return true; }; return { isItemInListByType, };};
Here is a step to add unit test in Nuxt Project


Setup For Test


  • Add Required Lib


bun add -d vitest @vitest/ui @vue/test-utils jsdom

  • Update your package.json to include a test script for running Vitest with Bun (Line 7)


"scripts": { "build": "nuxt build", "dev": "nuxt dev", "generate": "nuxt generate", "preview": "nuxt preview", "postinstall": "nuxt prepare", "test": "vitest"}

  • Configure Vitest - Create a vitest.config.ts file in the root of your project


import { defineConfig } from 'vitest/config';export default defineConfig({ test: { globals: true, environment: 'jsdom', setupFiles: './vitest.setup.ts', // Optional: Add setup file for global configurations },});

If you need to configure global settings (e.g., mocking or extending Jest matchers), create a vitest.setup.ts file


import '@testing-library/jest-dom';

Create a Test File


create a test on the same level as useCommonUtil.ts > useCommonUtil.test.ts
import useCommonUtil from './useCommonUtil';import { describe, it, expect } from 'vitest'describe('useCommonUtil', () => { const { isItemInListByType } = useCommonUtil(); const sampleList = [ { id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }, { id: 3, name: 'Item 3' }, ]; it("should return true if the item exists in the list by key", () => { const result = isItemInListByType(sampleList, "id", { id: 2, name: "Item 2" }); expect(result).toBe(true); }); it("should return false if the item does not exist in the list by key", () => { const result = isItemInListByType(sampleList, "id", { id: 4, name: "Item 4" }); expect(result).toBe(false); }); it("should return false if the list is empty", () => { const result = isItemInListByType([], "id", { id: 1, name: "Item 1" }); expect(result).toBe(false); }); it("should return false if the list is undefined", () => { const result = isItemInListByType(undefined, "id", { id: 1, name: "Item 1" }); expect(result).toBe(false); }); it("should return false if the key does not match any item in the list", () => { const result = isItemInListByType(sampleList, "name", { id: 1, name: "Nonexistent Item" }); expect(result).toBe(false); }); it("should handle objects with additional properties gracefully", () => { const extendedList = [ { id: 1, name: "Item 1", extra: "Extra 1" }, { id: 2, name: "Item 2", extra: "Extra 2" }, ]; const result = isItemInListByType(extendedList, "id", { id: 1, name: "Item 1", extra: "Extra 1" }); expect(result).toBe(true); });});

Run Tests

bun test
Sample Run Result
bun test v1.2.2 (c1708ea6)composables\useCommonUtil.test.ts:✓ useCommonUtil > should return true if the item exists in the list by keyItem with id=[object Object] not found in the list.✓ useCommonUtil > should return false if the item does not exist in the list by keyList is empty or undefined.✓ useCommonUtil > should return false if the list is emptyList is empty or undefined.✓ useCommonUtil > should return false if the list is undefinedItem with name=[object Object] not found in the list.✓ useCommonUtil > should return false if the key does not match any item in the list✓ useCommonUtil > should handle objects with additional properties gracefully 6 pass 0 fail 6 expect() callsRan 6 tests across 1 files.

Reference


#nuxt #Nuxt3 #unitTest


Fedora Considers Reducing The Scope That BIOS Systems Can Hold Up A Release

Given that non-UEFI BIOS systems are quite old at this point and Intel/AMD systems for the past number of years have all supported UEFI, another change proposal being considered this week by Fedoa Linux is limiting the release-blocking status of various (non-UEFI) BIOS systems...
phoronix.com/news/Fedora-Non-U…

Blender Now Supports Properly Importing & Exporting HDR Videos lxer.com/module/newswire/ext_l…

ตัวอย่าง TV Anime "Tensei shitara Dragon no Tamago datta ~Saikyou Igai Mezasanee~" โดย GA-CREW x Felix Film ออกอากาศภายในปี 2026

- Shunichi Toki➠Ilusia
- Ami Koshimizu➠Kami no Koe
- Miku Ito➠Myria

#tenseidragon

Morgen beim #CSDBerlin: 150 Einsatzkräfte & 60 Fahrzeuge von #TeamOrange sorgen für Sauberkeit und setzen ein Zeichen für #Diversität & Respekt. 🧡

Keine Party ohne Orange! 🧹🏳️‍🌈
Macht mit: Müll vermeiden, Papierkörbe nutzen, Pfand abgeben. Weitere Infos: bsr.de/bsr-gut-vorbereitet-150…

#BSR #CSD

Dear Hobbyspace!
On a whim I bought a Shifter Colour from Vallejo - and now I am at a loss on how to use it.

Has anyone some pointers for me? When? Where? How much? After painting? Instead of? I am clueless.

A friend put it on her Magnus-mini and said "it looks like someone came on him", so I think that's not the intended use.

#Hobbying #MiniaturePainting #WarhammerCommunity #Warhammer #PaintingMiniatures

This entry was edited (2 weeks ago)

Self-Care Check มาลองเช็คดูว่าคุณดูแลตัวเองครบทุกมิติหรือยัง แชร์วิธีการดูแลตัวเองในสไตล์คุณ ให้เพื่อนๆ ได้รับแรงบันดาลใจไปพร้อมๆ กัน #SelfCareCheck #HealthyMindHealthyBody #wellness #SelfLoveJourney #สุขภาพดีไม่มีขาย #ใส่ใจตัวเอง #MyHealthMyWay
yongchieng.com

📍 : readawrite.com/c/0d6bcf3edc61f…

👑 [ ลิงก์อ่านต่อ...ด้านบนเลยค่ะ 👆 ]

🌐 More Other Apps : linktr.ee/sunisayok

—————— ༻・ॐ・༺ ——————
#sunisayok #ชุมชนนักเขียน #readawrite #รีดอะไรท์ #meb #Fictionlog #ธัญวลัย #นิยาย #นิยายแนะนํา #แนะนำนิยาย #นิยายรัก #นิยายโรมานซ์ #นิยายรักดราม่า

Ayn Gaming Handhelds To See Better Linux Support With New Open-Source Driver

Ayn is a Chinese brand of handheld gaming devices that have included Arm-based devices shipping Android as well as AMD Ryzen powered handhelds with Windows 11 or even the option of installing Ubuntu. Better support for the Ayn x86 gaming handheld devices is on the way with patches posted for a new Ayn platform driver for the Linux kernel...
phoronix.com/news/Ayn-Handheld…

Red Hat Has Been Rewriting Bash-Based Greenboot In Rust

Greenboot is a generic health check framework for systemd on RPM-OSTree based Linux distributions. Red Hat engineers have worked on Greenboot as part of the likes of Fedora IoT and their other RPM-OSTree initiatives for checking on the overall system health with ease...
phoronix.com/news/Greenboot-Ba…

ตอนนี้มีบัตร UOB (กลายร่างมาจาก Citi), กรุงเทพ, แล้วก็กสิกร

กสิกรไม่ยอมเวฟค่าธรรมเนียมให้ เลยทำเรื่องปิดบัตรไปแล้วใบนึง (เหลืออีกใบ รอเงินเดือนเข้าก่อนแล้วจะปิดไปด้วย) บัตรกรุงเทพถ้าขอเวฟค่าธรรมเนียมไม่ได้ก็คงปิดเหมือนกัน

ส่วนบัตรหลักไปตกกับ UOB เหมือนเดิม วงเงินเยอะสุด

Unknown parent

mastodon - Link to source

jirayu

@sukino เอาจริงๆ ถ้าไม่ได้ถือมาตั้งแต่สมัย Citibank ผมก็คงไม่ได้ใช้แบงค์นี้ 555

เคยเอาแอพ TMRW สแกนจ่ายพร้อมเพย์แล้วยืนเหวอบ่อยมาก เงินออกแล้วแต่ไม่เข้า บางทีรอเป็นนาที

ส่วนบัตรเครดิตก็จัดยอดแบบงงมาก โยกอันนั้นใส่อันนี้วุ่นวายไปหมด

@jirayu +1 UOB เราว่าบัตรเครดิตมันสิทธิประโยชน์ดี วงเงินก็ให้เยอะมาก ติดอย่างเดียวระบบแย่ แอพ TMRW ก็แย่ แต่ใช้ไหมก็ใช้ 5555555
RE: social.vivaldi.net/@jirayu/114…


ตอนนี้มีบัตร UOB (กลายร่างมาจาก Citi), กรุงเทพ, แล้วก็กสิกร

กสิกรไม่ยอมเวฟค่าธรรมเนียมให้ เลยทำเรื่องปิดบัตรไปแล้วใบนึง (เหลืออีกใบ รอเงินเดือนเข้าก่อนแล้วจะปิดไปด้วย) บัตรกรุงเทพถ้าขอเวฟค่าธรรมเนียมไม่ได้ก็คงปิดเหมือนกัน

ส่วนบัตรหลักไปตกกับ UOB เหมือนเดิม วงเงินเยอะสุด


Google's Gemini CLI is an open source tool that lets you access Gemini directly from your terminal, and use it to read, edit and create files locally. I walk through how to install it on Ubuntu - assuming you want to! omgubuntu.co.uk/2025/07/how-to…

ผมไม่เห็นถึงข้อดีของการชวนให้ทะเลาะ ด้วยการให้ใส่ hashtag ปั่นต่าง ๆ จะทะเลาะกันเพราะ 2 ครอบครัวที่ไม่ได้ช่วยอะไรให้ประเทศดีขึ้นไปทำไม
.
และใครจะยิงก่อน ยิงหลังแล้วได้อะไร เลิกปั่นดีกว่าครับ
.
#Peace Please
.
#iamSK #Peace #สันติภาพ #សន្តិភាព #Cambodia #Thailand
.

หยาบคาย / ทหาร / สลิ่ม

Sensitive content

เดือนนี้เป็นเดือนที่สภาวะอารมณ์และจิตใจของเราไม่ดีเลย มีความ get annoyed สูงมาก แบบมากกกกกกก ซึ่งเราก็ลำดับสาเหตุที่มาที่ไป และเข้าใจว่าทำไมตัวเองหงุดหงิดและรำคาญสิ่งต่าง ๆ รอบตัวมาก คือรู้ทันความคิดตัวเอง แต่เราก็ไม่สามารถจะหยุดอันความนอยของเราได้

ความนอยของเราส่งผลให้เราอยากลาออกจากงาน อยากเปลี่ยนที่ทำงาน แต่เหมือนเราอยู่ใน comfort zone มานาน อยู่กับสิ่งที่ชอบมานาน รู้สึกว่าการออกจาก comfort zone นี้คือการเริ่มต้นใหม่กับสาขาวิชาที่เราไม่มีพื้นฐานเลย มีพื้นฐานบ้าง อาจจะไม่ได้เกี่ยวกับความชอบเราเลย หรือเป็นสิ่งที่ตรงจริตกับเราน้อยกว่าที่เราเป็นอยู่ 😅

สุดท้าย คือ ในเมื่อทำอะไรไม่ได้ก็จงนอยกับสิ่งที่เลือกเองต่อไป

🚨 ป้ายยาเรื่องใหม่แบบสับ! #เมียที่เขาไม่ต้องการ อัปตอนแรกแล้วค่าาา! 🚨
.
อ่านทุกแพลตฟอร์มง่าย ๆ ได้ที่... 👇
📚 นิยายเรื่อง : เมียที่เขาไม่ต้องการ
✍️ นามปากกา : SUNISAYOK
.
🫶 Thx 🫶
illust : MMMZ
Typo : Monita
.
—————— ༻・ॐ・༺ ——————
#sunisayok #ชุมชนนักเขียน #readawrite #รีดอะไรท์ #meb #Fictionlog #ธัญวลัย #นิยาย #นิยายแนะนํา #แนะนำนิยาย #นิยายรัก #นิยายโรมานซ์ #นิยายรักดราม่า

blog: Tai Tham Updated, Thai Noi Revisited
thep.blogspot.com/2025/07/tai-…

update ฟอนต์และเพิ่มผังแป้นพิมพ์บน Windows สำหรับอักษรธรรม, เลือกวิธีการสำหรับอักษรไทยน้อยแล้วปรับ implementation

I found a technician who'd work on a Linux machine, and she solved my problem (I had no wifi whatsoever) the same day that she received it.

I realize the culture of Linux "fix it yourself!" and I tried. I got a buddy to help. We couldn't figure it out, so I paid a professional to fix it and then tell me how she did it.

I want to normalize this. For Linux to be viable, it can't just be a hobby OS. Paying pros to fix it, and set it up for you, is part of that.

#linux #foss #floss #OpenSource