name: javascript-expert-tests
skill: javascript-expert
version: 1.0.0
cases:
  - id: prefer-composition
    description: Should recommend composition over inheritance for code reuse
    prompt: I have a base class Vehicle with shared logic and 6 subclasses. Adding new vehicle types keeps requiring changes to the base class. How should I refactor this?
    expected:
      contains_any:
        - composition
        - composable
        - functions
        - mixin
        - inheritance
      min_length: 80
    tags:
      - core
      - patterns

  - id: async-await-default
    description: Should recommend async/await as the default async pattern
    prompt: Should I use callbacks, Promises with .then(), or async/await for my Node.js API handlers?
    expected:
      contains_any:
        - async/await
        - async
        - await
      min_length: 60
    tags:
      - core
      - async

  - id: strict-typescript
    description: Should advocate for strict TypeScript and avoiding any
    prompt: Our TypeScript project has strict mode disabled and uses 'any' in about 30% of type annotations. Is this a problem?
    expected:
      contains_any:
        - strict
        - "any"
        - unknown
        - type safety
        - code smell
      min_length: 80
    tags:
      - core
      - typescript

  - id: immutability-default
    description: Should prefer const and immutability by default
    prompt: Should I use let or const for most variable declarations in JavaScript?
    expected:
      contains_any:
        - const
        - immutable
        - immutability
        - reassign
      min_length: 60
    tags:
      - core
      - fundamentals

  - id: explicit-error-handling
    description: Should reject swallowing errors silently
    prompt: "Is this error handling pattern okay? try { await saveUser(data); } catch (e) { }"
    expected:
      contains_any:
        - swallow
        - silent
        - log
        - handle
        - rethrow
        - re-throw
        - ignore
      min_length: 60
    tags:
      - core
      - error-handling

  - id: coding-easy-debounce
    description: "Coding challenge (easy): Implement a debounce utility function"
    prompt: "Write a TypeScript debounce function that delays invoking a callback until after a specified wait time has elapsed since the last call. It should be generic, preserve the argument types, and return a cancel method."
    expected:
      contains_any:
        - setTimeout
        - clearTimeout
        - cancel
        - delay
      contains:
        - function
      not_contains:
        - "I can't write"
      min_length: 100
    tags:
      - coding-easy

  - id: coding-medium-event-emitter
    description: "Coding challenge (medium): Implement a type-safe event emitter"
    prompt: "Write a TypeScript EventEmitter class that is generic over an event map type. It should support on, off, once, and emit methods. The event map should enforce that listeners receive the correct payload type for each event name. Include proper cleanup to prevent memory leaks."
    expected:
      contains_any:
        - Map
        - Set
        - listener
        - emit
        - delete
      contains:
        - class
      min_length: 200
    tags:
      - coding-medium

  - id: coding-hard-task-queue
    description: "Coding challenge (hard): Implement a concurrent async task queue with retry and backoff"
    prompt: "Write a TypeScript TaskQueue class that processes async tasks with configurable max concurrency. It should support: priority ordering (higher priority tasks run first), retry with exponential backoff on failure, a per-task timeout, and an abort method that cancels all pending tasks. Return results via a promise per task."
    expected:
      contains_any:
        - async
        - await
        - Promise
        - queue
        - retry
        - concurrency
      contains:
        - class
      min_length: 300
    tags:
      - coding-hard
