jasmine-jquery is a testing utility that extends the Jasmine JavaScript Testing Framework with custom matchers specifically designed for jQuery elements and an an API for managing HTML, CSS, and JSON fixtures. It facilitates the testing of DOM interactions and external data loading in front-end applications, providing a convenient way to assert jQuery object states and manipulate test environments. The current stable version, 2.1.1, was released in May 2015. The project appears to be largely unmaintained since 2017, meaning there is no active release cadence, and it primarily targets older testing setups that rely on global script inclusions and jQuery. Its key differentiators include a comprehensive set of jQuery-specific matchers like `toBeVisible`, `toHaveAttr`, and `toContainElement`, as well as a convenient fixture loading mechanism that simplifies isolated component testing by providing `loadFixtures`, `setFixtures`, and `clearFixtures` globals.
npm install jasmine-jqueryVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `jasmine-jquery` within a Jasmine test suite. It shows how to load HTML content using `loadFixtures` (assuming a configured `fixturesPath`) and then apply various custom jQuery matchers like `toExist`, `toHaveAttr`, `toBeChecked`, `toBeVisible`, `toBeHidden`, `toContainText`, and `toContainElement` to assert properties and states of DOM elements.
For module-based projects, consider alternative DOM testing utilities like `@testing-library/jest-dom` or integrate `jasmine-jquery` through global script loading in a test HTML runner or a shimming setup. Ensure `jQuery` and `jasmine` are loaded globally *before* `jasmine-jquery.js`.
Ensure `jQuery` is exposed globally (e.g., `window.jQuery = require('jquery')` or by loading jQuery via a `<script>` tag before `jasmine-jquery`). If using a module bundler, explicitly expose `jQuery` to the `window` object before `jasmine-jquery` is processed.For new projects or migrations, consider modern DOM testing libraries that align with current front-end development practices. For existing projects, be aware of the lack of updates and potential compatibility issues with newer jQuery or Jasmine versions.
Ensure `jasmine-jquery.js` is loaded into the global scope via a `<script>` tag in your test runner HTML, or via a pre-processor in your test setup, *before* your test files run. Also, verify `jQuery` and `Jasmine` itself are loaded globally beforehand.
Double-check the loading order: `jQuery` -> `Jasmine` -> `jasmine-jquery.js`. Ensure there are no JavaScript errors during the loading of `jasmine-jquery.js` that might prevent it from registering its matchers.
Make certain that `jQuery` is loaded and accessible globally *before* `jasmine-jquery.js` is loaded. If using a module bundler, ensure `jQuery` is explicitly exposed to the global `window` object.
Verify that `jasmine.getFixtures().fixturesPath` is correctly configured in your test setup to point to the directory containing your fixture files. Ensure the fixture file name and extension are correct and that the file is actually present and accessible at that path.