Unit Test
اختبار الوحدة
GLS-000149
Definition
A test that checks a single function or component in isolation — fast and reliable.
اختبار يفحص دالة أو مكوّن واحدًا بشكل معزول — سريع وموثوق.
Why It Matters
Unit tests catch bugs early — before they reach production. A test for the glossary slug builder catches edge cases like 'Next.js' → 'nextjs' correctly.
اختبارات الوحدة تكتشف الأخطاء مبكرًا — قبل وصولها إلى الإنتاج. اختبار لباني slug الغلوساري يكتشف الحالات الحافة مثل 'Next.js' → 'nextjs' بشكل صحيح.
Full Definition
Example Usage
“test('slug builder', () => { expect(buildSlug('Next.js')).toBe('nextjs') })”
“test('باني slug', () => { expect(buildSlug('Next.js')).toBe('nextjs') })”
AI Builder Tips
Avoid these mistakes when using Unit Test:
Testing implementation details instead of behavior (tests break when you refactor even if behavior is unchanged)
100% coverage target — forces useless tests on trivial code
Sign in to unlock guided AI explanations from AI Teacher.
Generate a Prompt
Copy this prompt and use it directly with any AI model — no setup needed.
Help me build a project using Unit Test. Explain: 1. What is Unit Test and why it matters 2. The core architecture and required tools 3. Step-by-step implementation plan 4. Common mistakes to avoid: Testing implementation details instead of behavior (tests break when you refactor even if behavior is unchanged), 100% coverage target — forces useless tests on trivial code 5. Best practices and production tips