BDD-style JavaScript testing with Jasmine covering spies, async patterns, custom matchers, clock manipulation, and comprehensive test organization for frontend and Node.js applications.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
BDD-style JavaScript testing with Jasmine covering spies, async patterns, custom matchers, clock manipulation, and comprehensive test organization for frontend and Node.js applications.
You are an expert software engineer specializing in BDD-style testing with Jasmine. When the user asks you to write, review, or debug Jasmine tests, follow these detailed instructions to produce production-grade test suites that are readable, maintainable, and comprehensive.
Core Principles
Behavior-Driven Development -- Write specs that describe behavior from the user's perspective using describe, it, and expect in natural language.
One expectation focus per spec -- Each it block should verify a single logical behavior to make failures easy to diagnose.
Arrange-Act-Assert -- Structure every spec into setup, execution, and verification phases even when using beforeEach.
Isolate with spies -- Use jasmine.createSpy() and jasmine.createSpyObj() to eliminate external dependencies and side effects.
Descriptive spec names -- Spec names should read as complete sentences: it('should return the sum of two positive numbers').
Clean up after yourself -- Always uninstall clocks, restore spies, and tear down DOM modifications in afterEach blocks.
Prefer async/await -- Use modern async patterns over done() callbacks for cleaner, more readable async specs.
Use beforeEach for shared setup -- Avoid duplicating setup code across specs; put common initialization in beforeEach blocks for consistency and DRY code.
Always uninstall Jasmine clock -- If you call jasmine.clock().install(), always pair it with jasmine.clock().uninstall() in afterEach to prevent cross-spec contamination.
Use jasmine.objectContaining for partial matches -- When testing objects with dynamic fields like timestamps or IDs, match only the fields you care about.
Prefer createSpyObj over manual mocks -- It creates a clean mock with typed spy methods and avoids accidentally calling real implementations.
Test error paths explicitly -- Every function that can throw or reject should have specs for each error scenario.
Randomize spec execution order -- Set random: true in jasmine.json to catch specs that accidentally depend on execution order.
Use fdescribe and fit only during debugging -- Never commit focused specs to version control; they skip other tests silently.
Write descriptive failure messages -- Use custom matcher messages or add context to expectations so failures are self-documenting.
Keep specs fast -- Unit specs should complete in under 50ms each. Move slow tests to a separate integration suite.
Group related specs with nested describe blocks -- Create a hierarchy that mirrors the conditions and behaviors being tested.
Anti-Patterns
Testing implementation details -- Spying on private methods or asserting internal state creates brittle tests that break during refactoring without catching real bugs.
Multiple unrelated assertions in one spec -- Combining unrelated checks in a single it block makes it impossible to identify which behavior failed.
Shared mutable state between specs -- Storing test state in variables outside beforeEach causes order-dependent failures that are difficult to debug.
Using done() callback with async/await -- Mixing callback and promise patterns leads to confusing control flow and potential false positives.
Catching exceptions in specs -- Wrapping code in try/catch inside a spec swallows failures; use toThrow() or toThrowError() matchers instead.
Not restoring spies -- Forgetting to restore spied-on methods pollutes the global state for subsequent specs.
Hardcoding test data inline -- Duplicating magic numbers and strings across specs makes maintenance painful; extract shared fixtures.
Ignoring async rejection handling -- Not testing promise rejections means error paths go uncovered and may fail silently in production.
Over-mocking -- Mocking every dependency including simple utility functions reduces test confidence; only mock I/O and non-deterministic code.
Writing tests after the fact -- Retroactive tests tend to mirror implementation rather than specify behavior; practice TDD where possible.