It Testing Framework
"It" is a lightweight, behavior-driven development (BDD) style testing framework designed for both Node.js and browser environments, last known at version 1.1.1. It supports various asynchronous test patterns, including Promises and the traditional Mocha-style `done(err)` callback, and explicitly avoids polluting the global namespace. Key features include cross-environment compatibility, AMD support for browsers, multiple reporters (such as TAP for CI systems), and proper exit codes. Unlike some frameworks, `it` requires explicit CommonJS import and passes its context (`it`) into `describe` and `test` callbacks, promoting isolated test suites. Its development appears to be largely inactive, with the last stable release dating back significantly, making it less suitable for modern JavaScript projects requiring native ESM support or contemporary testing features.
Common errors
-
ReferenceError: it is not defined
cause Attempting to use `it.describe` or `it.should` without correctly importing the `it` module first, or trying to use `it` globally in a scope where it hasn't been passed as an argument.fixEnsure you have `const it = require('it');` at the top of your test file, and that the `it` object is passed into your `describe` and test callbacks: `it.describe('My Suite', function(it) { ... })`. -
TypeError: assert.isFunction is not a function
cause Using `assert.isFunction` or similar non-standard `assert` methods with Node.js's built-in `assert` module, which does not provide these methods.fixReplace calls to `assert.isFunction` with standard Node.js `assert` methods like `assert.strictEqual(typeof myVar, 'function')` or consider using an alternative assertion library like Chai (`assert`, `expect`, or `should` styles) which offers a broader range of assertions. -
SyntaxError: Cannot use import statement outside a module
cause Trying to use `import { it } from 'it';` in a Node.js environment that is not configured for ES Modules, or when the `it` package itself is a CommonJS module.fixUse the CommonJS `require` syntax: `const it = require('it');`. If you are in an ES Module context, you may need to use `import it from 'it'` if it provides a default export, or consider a build step that transforms CommonJS to ESM.
Warnings
- breaking The `it` framework primarily uses CommonJS modules (`require`) and does not natively support ECMAScript Modules (ESM) `import` syntax. Attempting to use `import` directly in modern Node.js environments configured for ESM will result in errors.
- gotcha The `assert` module examples in the original `it` documentation (e.g., `assert.isFunction`) may imply a custom `assert` library or an older Node.js environment. Node.js's built-in `assert` module (especially in modern versions) primarily offers methods like `assert.strictEqual`, `assert.ok`, etc., and does not include `isFunction` directly. Using `assert.isFunction` with Node's built-in `assert` will result in a `TypeError`.
- gotcha The `it` object is explicitly passed as an argument to `it.describe` and individual `it.should` (or `it()`) callbacks. This means `it` is not a global variable available throughout your test file. If you omit the parameter in a nested describe or test, `it` will be `undefined` within that scope.
- deprecated This package appears to be abandoned or in long-term maintenance, with no significant updates in recent years. Its reliance on older Node.js versions (>=0.10.1) and older CI systems (Travis CI, Testling CI) suggests it may not be compatible with newer JavaScript features, Node.js APIs, or modern testing practices.
Install
-
npm install it -
yarn add it -
pnpm add it
Imports
- it
import { it } from 'it';const it = require('it'); - it.describe
describe('suite name', function() { /* ... */ });const it = require('it'); it.describe('suite name', function(it) { /* ... */ }); - it.should
should('do something', function() { /* ... */ });const it = require('it'); it.describe('suite', function(it) { it.should('do something', function() { /* ... */ }); });
Quickstart
var Person = function (name, age) {
this.name = name;
this.age = age;
this.getOlder = function (years) {
if (years > 0) {
this.age = this.age + years;
}
};
};
var it = require("it"),
assert = require("assert"); // Node.js built-in assert module
it.describe("Person Object Tests", function (it) {
it.should("correctly set name", function () {
var person = new Person("Alice", 30);
assert.strictEqual(person.name, "Alice");
});
it.should("correctly set age", function () {
var person = new Person("Bob", 25);
assert.strictEqual(person.age, 25);
});
it.describe("#getOlder method", function (it) {
it.should("increase age by positive numbers", function () {
var person = new Person("Charlie", 40);
person.getOlder(5);
assert.strictEqual(person.age, 45);
});
it.should("not modify age for negative numbers", function () {
var person = new Person("David", 20);
person.getOlder(-3);
assert.strictEqual(person.age, 20);
});
});
});
// To run this, save as a .js file and execute with Node.js: `node your-test-file.js`.
// Alternatively, if `it` CLI is installed globally: `it your-test-file.js`.