Registry / testing / ospec

ospec

JSON →
library4.2.1jsnpmunverified

ospec is a lightweight and "noiseless" JavaScript testing framework, currently at version 4.2.1. It aims for terser and faster test code compared to alternatives like Mocha, Jasmine, or Tape, emphasizing readability through its Subject-Verb-Object assertion structure. The framework includes features for test grouping, asynchronous tests, `before/after` hooks, test exclusivity (`.only`), and spies for mocking functions. Its core design principle is to regulate test-space configuration to promote focus on testing logic and encourage uniform test suites. The project maintains a small footprint, aiming for around 800 lines of code after a planned API surface change, with a current release cadence that reflects ongoing development and refinements.

testing
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ospec exports the main 'o' function as a default export in both CommonJS and ESM. Avoid destructuring 'o' from the require statement.

import o from 'ospec'

For CommonJS environments, 'o' is the direct module.exports. Using ESM import syntax in a CJS context will result in syntax errors.

const o = require('ospec')

'o.spec' is a method on the default exported 'o' function, not a named export itself. Import 'o' first, then access 'spec' as a property.

import o from 'ospec'; o.spec('group', () => { /* ... */ })

Demonstrates basic test definition, grouping, nested groups, assertions, spy usage, and asynchronous testing with ospec.

import o from 'ospec'; // Basic test and assertions o.spec("math operations", function() { o("addition works", function() { o(1 + 1).equals(2)("basic addition assertion"); o(2 + 2).equals(4); }); o("subtraction works", function() { o(1 - 1).notEquals(2)("basic subtraction assertion"); }); // Nested test groups o.spec("arithmetics details", function() { o("multiplication also works", function() { o(2 * 3).equals(6); }); }); }); // Example with o.spy for function call tracking function executeCallback(cb, arg) { cb(arg); } o.spec("executeCallback()", function() { o("calls the provided callback with the argument", function() { var spy = o.spy(); executeCallback(spy, "test-argument"); o(spy.callCount).equals(1)("spy should be called once"); o(spy.args[0]).equals("test-argument")("first call argument should match"); o(spy.calls[0].args).deepEquals(["test-argument"])("full call arguments should deep equal"); }); }); // To run the tests, typically you would run this file via the `ospec` CLI or call o.run() // Assuming a simple setup where tests are executed on file load, // or for explicit execution, the 'ospec' runner needs to be invoked. // For demonstration, we simulate running all defined tests. // In a real CLI setup, this explicit `o.run()` might not be needed. // However, if running directly in Node, it might be. Let's omit for general quickstart. // A typical setup would involve `npx ospec my-tests.js` // Example of an async test o.spec("async operations", function() { o("handles promises correctly", function(done) { Promise.resolve(5).then(result => { o(result).equals(5); done(); // Important for async tests to signal completion }); }); });
Debug
Known footguns
breakingThe ospec API surface is currently undergoing changes. Both legacy and updated APIs are present to ease transition, but users relying on older patterns should anticipate potential breaking changes in future major releases once legacy code is removed.
gotchaAsynchronous tests in ospec require calling the `done()` callback or returning a Promise to signal completion. Failing to do so will cause the test to exit prematurely or time out.
gotchaWhen providing a description for an assertion, ospec uses a function call `o(...).equals(...)('description')` or template literal syntax `o(...).equals(...) `description``. Using a comma `o(...).equals(..., 'description')` is incorrect and will be treated as an additional argument to the assertion method.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources