Givens is a testing utility designed to facilitate clean, maintainable, and side-effect-free test setups, primarily for JavaScript and TypeScript projects using Jest, Mocha, or Jasmine. Its behavior is inspired by RSpec's 'given' keyword, offering a familiar pattern for developers with Ruby backgrounds. The library helps prevent common testing pitfalls such as cross-contamination between tests, order-dependent tests, and unpredictable behavior when running subsets of tests (e.g., with `.only` or `.skip`). It achieves this by managing a cached, scoped value for 'given' variables, ensuring values are fresh for each test and correctly reverted across `describe` blocks. The current stable version is 1.3.9, with a recent cadence of security and dependency updates, indicating active maintenance rather than feature-heavy releases.
npm install givensVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define and override 'given' variables with type safety in TypeScript, showing how `givens` manages scope and caching.
Ensure Jest configuration uses `setupFilesAfterEnv: ['givens/setup.js']`.
Upgrade to v1.3.0 or later and adopt the recommended `getGiven<MyVars>()` pattern for improved type safety.
Use `givens` exclusively within Node.js testing environments (e.g., Jest, Mocha, Jasmine running in Node).
Regularly update `givens` to its latest version (e.g., using `npm update givens` or `yarn upgrade givens`) and monitor for new releases.
For local usage: `import getGiven from 'givens'; const given = getGiven();`. For global usage: configure your test runner with `setupFilesAfterEnv: ['givens/setup.js']` (for Jest) or equivalent.
Ensure you call `const given = getGiven();` after importing `getGiven`, or verify your test runner's global setup is correctly configured and applied.
Update your TypeScript interface (e.g., `interface SomeVars { myKey: SomeType; }`) to include all keys you intend to use with `given`.No dependency data recorded yet.