Registry / testing / karma-jasmine

karma-jasmine

JSON →
library5.1.0jsnpmunverified

karma-jasmine is a Karma plugin that serves as an adapter for the Jasmine testing framework, enabling developers to run their Jasmine-based unit tests within the Karma test runner environment. The current stable version is 5.1.0, released in June 2022, with a consistent release cadence addressing bug fixes, dependency updates (including `jasmine-core`), and minor feature enhancements. It primarily functions by providing the `jasmine` framework to Karma's configuration, allowing seamless integration and execution of Jasmine specs. Key differentiators include its tight coupling with the Karma ecosystem, offering features like custom spec filtering, debug-by-URL capabilities for focused testing, and basic sharding support. This package is essential for projects using Karma for test automation and Jasmine for writing their tests, abstracting away the complexities of setting up the two together.

npm install karma-jasmine
INSTALL
IMPORT
SIG · KARMA-JASMINE
K
karma-jasmine
testingjavascriptv5.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

frameworks
config.set({ frameworks: ['jasmine'] })
import 'karma-jasmine';
karma-jasmine is a Karma plugin configured in `karma.conf.js`, not directly imported into application or test code via `import` or `require`.
client.jasmine
config.set({ client: { jasmine: { random: true } } })
Jasmine configuration options are passed via `config.client.jasmine` in `karma.conf.js`.
client.args (grep)
config.set({ client: { args: ['--grep', '<pattern>'] } })
karma start --grep=<pattern>
While `--grep` works directly with `karma run`, embedding it in `client.args` ensures it's applied consistently across runs configured in `karma.conf.js`.

This quickstart demonstrates how to configure Karma to use karma-jasmine, specifying test files, browsers, and passing Jasmine-specific options directly via the `client.jasmine` property in `karma.conf.js`.

const path = require('path'); module.exports = function(config) { config.set({ frameworks: ['jasmine'], files: [ // Assuming your test files are in a 'spec' directory path.resolve(__dirname, 'src/**/*.js'), path.resolve(__dirname, 'spec/**/*.spec.js') ], browsers: ['ChromeHeadless'], reporters: ['progress'], autoWatch: true, singleRun: false, client: { jasmine: { random: true, seed: '12345', oneFailurePerSpec: false, failFast: false, timeoutInterval: 5000 }, // Example of custom spec filter, though typically done via `karma run -- --grep` or `jasmine.getEnv().configure` // args: ['--grep', 'spec that succeeds'] } }); };
Debug
Known issues
breakingVersion 5.0.0 of karma-jasmine dropped support for Node.js 10. Projects using Node.js 10 or older will need to upgrade their Node.js environment to version 12 or higher to use karma-jasmine v5.
fix
Upgrade Node.js to version 12 or newer. Use `nvm install 16 && nvm use 16` (or desired version) or update `package.json` engines and re-install dependencies.
affects: >=5.0.0
breakingWith the release of v5.0.0, the `karma` peer dependency was strictly limited to `^6.0.0`. Older versions of Karma are no longer supported by `karma-jasmine` v5.
fix
Ensure your project's `karma` dependency is updated to `^6.0.0` (e.g., `npm install karma@^6.0.0 --save-dev`).
affects: >=5.0.0
breakingVersion 4.0.0 dropped support for Node.js 8. Projects still on Node.js 8 will encounter issues. This version also added support for Node.js 14.
fix
Upgrade Node.js to version 10 or newer (ideally 14+ for v4.0.0) if you intend to use `karma-jasmine` v4.
affects: >=4.0.0 <5.0.0
gotchaIncorrectly configuring `files` array in `karma.conf.js` can lead to tests not being found or unexpected execution order. Ensure test files and any required source files are correctly included.
fix
Verify that your `files` array accurately points to all necessary source code and test spec files. Use glob patterns carefully and consider `included: false` for files that should only be served, not executed globally.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'karma' from '<path>'
Karma is a peer dependency and must be installed separately.
fix
Install Karma: `npm install karma --save-dev`
TypeError: config.set is not a function
Attempting to use `require('karma')` directly to configure Karma instead of exporting a function that receives the config object.
fix
Ensure `karma.conf.js` exports a function: `module.exports = function(config) { /* ... */ }`.
No specs found
The `files` array in `karma.conf.js` does not correctly point to any Jasmine spec files.
fix
Review the `files` array in `karma.conf.js` and ensure the glob patterns or file paths accurately include your Jasmine test files (e.g., `['spec/**/*.js']`).
Jasmine is not defined
Jasmine environment functions (e.g., `describe`, `it`, `expect`) are globally available in spec files but not necessarily in auxiliary scripts or outside the test execution context.
fix
Ensure your Jasmine spec files are correctly loaded by Karma-Jasmine and that you are writing test code within `describe` blocks. This error can also occur if `frameworks: ['jasmine']` is missing from `karma.conf.js`.
Upgrade
Version history
5.1.0latest on npm
Audit
Dependencies
karmarequiredPeer dependency, karma-jasmine is an adapter plugin for Karma.
Agent activity
2 hits · last 30 days
node
2
Resources
karma-jasmine — npm install karma-jasmine · libregistry