← Back to jasmine/jasmine

How to Deploy & Use jasmine/jasmine

Jasmine Testing Framework - Deployment and Usage Guide

Prerequisites

  • Node.js: Version 20, 22, or 24 (required for running Jasmine)
  • npm: Version 6.0 or higher (typically bundled with Node.js)
  • Supported Browsers: Safari 26+, Chrome (evergreen), Firefox (evergreen, 102+, 115+, 128+, 140+), Edge (evergreen)
  • JavaScript Runtime: Any modern JavaScript environment that supports ES5+

Installation

Option 1: Using npm (Recommended)

# Install globally for command-line usage
npm install -g jasmine

# Initialize Jasmine in your project
jasmine init

# Install as a dev dependency
npm install --save-dev jasmine

Option 2: Manual Installation

  1. Clone the repository:
git clone https://github.com/jasmine/jasmine.git
cd jasmine
  1. Install dependencies:
npm install
  1. Build the project:
npm run build

Option 3: Browser Integration

Download the standalone distribution from the releases page and include it in your HTML:

<script src="jasmine.js"></script>
<script src="jasmine-html.js"></script>

Configuration

Environment Variables

Jasmine doesn't require specific environment variables, but you can configure it through:

  1. Configuration File: Create a jasmine.json file in your project root:
{
  "spec_dir": "spec",
  "spec_files": [
    "**/*[sS]pec.js"
  ],
  "helpers": [
    "helpers/**/*.js"
  ],
  "stopSpecOnExpectationFailure": false,
  "random": false
}
  1. Timeout Configuration: Set default timeout interval:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; // 10 seconds

API Keys

No API keys are required for Jasmine itself, but you may need them for testing external services in your specs.

Build & Run

Running Tests Locally

Node.js Environment

# Run all specs
jasmine

# Run with specific config
jasmine --config=jasmine.json

# Run with random order
jasmine --random=true

# Run with seed
jasmine --seed=1234

Browser Environment

  1. Create an HTML spec runner:
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Jasmine Spec Runner v3.99.0</title>
  <link rel="stylesheet" href="jasmine.css">
  <script src="jasmine.js"></script>
  <script src="jasmine-html.js"></script>
  <script src="boot.js"></script>
</head>
<body>
</body>
</html>
  1. Add your spec files to the HTML file and open it in a browser.

Development Mode

# Watch for changes and re-run tests
npm run test:watch

Production Mode

# Run tests once
npm test

Deployment

Node.js Applications

Deploy your Jasmine tests alongside your application code. No special deployment steps are needed for the testing framework itself.

Browser Applications

Include Jasmine in your build process:

  1. Webpack/Vite: Add Jasmine as a dev dependency and configure test scripts
  2. CI/CD: Run Jasmine tests in your pipeline before deployment

Continuous Integration

Configure your CI/CD pipeline to run Jasmine tests:

# GitHub Actions example
name: Test
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-node@v2
      with:
        node-version: '20'
    - run: npm ci
    - run: npm test

Troubleshooting

Common Issues and Solutions

1. "Cannot find module 'jasmine'" Error

Solution: Ensure Jasmine is installed in your project:

npm install --save-dev jasmine

2. Tests Not Running in Browser

Solution: Check that all required Jasmine files are included:

  • jasmine.js
  • jasmine-html.js
  • boot.js
  • jasmine.css

3. Timeout Errors

Solution: Adjust the timeout interval:

jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000; // 15 seconds

Or set per-spec timeout:

it("should complete async operation", function(done) {
  // async test
}, 10000); // 10 second timeout

4. Global Errors Not Being Caught

Solution: Ensure global error handling is configured:

const env = jasmine.getEnv();
env.installGlobalErrors();

5. Pretty Print Issues with Large Objects

Solution: Adjust pretty print limits:

j$.MAX_PRETTY_PRINT_DEPTH = 5;
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 20;
j$.MAX_PRETTY_PRINT_CHARS = 500;

6. Tests Running in Wrong Order

Solution: Control test order:

jasmine --random=false

Or use focused specs for debugging:

fdescribe("focused suite", function() {
  // Only this suite will run
});

fit("focused spec", function() {
  // Only this spec will run
});

Getting Help