DOM-less simple JavaScript BDD testing framework for Node.js
npx @tessl/cli install tessl/npm-jasmine-node@3.0.0jasmine-node is a Node.js BDD testing framework that brings Pivotal Lab's Jasmine (version 1) to server-side JavaScript environments. It provides DOM-less testing capabilities with comprehensive reporting, asynchronous test support, and integration with build systems and continuous integration platforms.
npm install jasmine-node -gconst jasmine = require("jasmine-node");For global usage (after global installation):
jasmine-node spec/// In your spec files (must match *spec.js pattern)
describe("Calculator", function() {
it("should add two numbers correctly", function() {
const result = 2 + 3;
expect(result).toEqual(5);
});
it("should handle async operations", function(done) {
setTimeout(function() {
expect(true).toBe(true);
done();
}, 100);
});
});Run tests:
jasmine-node spec/jasmine-node is built around several key components:
Core BDD functions for writing test suites and specifications. Includes support for setup/teardown, test organization, and assertions.
function describe(description, specDefinitions);
function it(description, specFunction, timeout);
function beforeEach(setupFunction, timeout);
function afterEach(teardownFunction, timeout);
function expect(actual);Comprehensive CLI with options for test execution, file watching, output formatting, and CI integration.
// CLI execution options
interface CliOptions {
autotest?: boolean;
watch?: string[];
coffee?: boolean;
color?: boolean;
verbose?: boolean;
junitreport?: boolean;
teamcity?: boolean;
growl?: boolean;
match?: string;
timeout?: number;
}Multiple reporter formats for different environments including terminal output, CI integration, and notifications.
class TerminalReporter {
constructor(config: ReporterConfig);
}
class TerminalVerboseReporter {
constructor(config: ReporterConfig);
}
class TeamcityReporter {
constructor(config: ReporterConfig);
}
interface ReporterConfig {
print?: Function;
color?: boolean;
onComplete?: Function;
includeStackTrace?: boolean;
}Advanced functionality including RequireJS support, CoffeeScript integration, file watching, and custom configuration.
function executeSpecsInFolder(options: ExecutionOptions);
function loadHelpersInFolder(folder: string, matcher: RegExp);
interface ExecutionOptions {
specFolders: string[];
onComplete?: Function;
isVerbose?: boolean;
showColors?: boolean;
useRequireJs?: boolean | string;
regExpSpec?: RegExp;
}// Global BDD functions
declare function describe(description: string, specDefinitions: () => void): void;
declare function it(description: string, specFunction: (done?: () => void) => void, timeout?: number): void;
declare function beforeEach(setupFunction: (done?: () => void) => void, timeout?: number): void;
declare function afterEach(teardownFunction: (done?: () => void) => void, timeout?: number): void;
declare function xdescribe(description: string, specDefinitions: () => void): void;
declare function xit(description: string, specFunction: () => void): void;
// Expectations and spies
declare function expect(actual: any): jasmine.Matchers;
declare function spyOn(object: any, method: string): jasmine.Spy;
declare function waitsFor(latchFunction: () => boolean, timeoutMessage?: string, timeout?: number): void;
declare function waits(timeout: number): void;
declare function runs(asyncMethod: () => void): void;
// Main jasmine object
declare namespace jasmine {
interface Matchers {
toBe(expected: any): boolean;
toEqual(expected: any): boolean;
toMatch(expected: string | RegExp): boolean;
toBeNull(): boolean;
toBeUndefined(): boolean;
toBeTruthy(): boolean;
toBeFalsy(): boolean;
toContain(expected: any): boolean;
toBeGreaterThan(expected: number): boolean;
toBeLessThan(expected: number): boolean;
toThrow(expected?: any): boolean;
not: Matchers;
}
interface Spy {
andReturn(value: any): Spy;
andThrow(exception: any): Spy;
andCallThrough(): Spy;
andCallFake(fakeFunction: Function): Spy;
calls: any[];
mostRecentCall: { args: any[] };
argsForCall: any[][];
callCount: number;
}
interface Env {
defaultTimeoutInterval: number;
execute(): void;
addReporter(reporter: any): void;
}
function getEnv(): Env;
function getGlobal(): any;
}