CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jasmine-node

DOM-less simple JavaScript BDD testing framework for Node.js

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

jasmine-node

jasmine-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.

Package Information

  • Package Name: jasmine-node
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install jasmine-node -g
  • License: MIT

Core Imports

const jasmine = require("jasmine-node");

For global usage (after global installation):

jasmine-node spec/

Basic Usage

// 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/

Architecture

jasmine-node is built around several key components:

  • Core Jasmine Engine: Modified Jasmine 1.3.1 with Node.js adaptations
  • CLI Interface: Command-line tool with extensive configuration options
  • Reporter System: Multiple output formats (terminal, verbose, TeamCity, JUnit XML, Growl)
  • Spec Discovery: Automatic test file discovery and loading
  • Async Support: Enhanced asynchronous testing with done() callbacks
  • Multi-Format Support: JavaScript, CoffeeScript, and Literate CoffeeScript specs
  • RequireJS Integration: Module loading support for AMD-style projects

Capabilities

Test Writing

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);

Test Writing

Command Line Interface

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;
}

CLI Usage

Reporters and Output

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;
}

Reporters and Output

Advanced Features

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;
}

Advanced Features

Core Types

// 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;
}
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/jasmine-node@3.0.x
Publish Source
CLI
Badge
tessl/npm-jasmine-node badge