chartjs-test-utils is a dedicated utility package designed to simplify and standardize the testing of Chart.js applications and plugins. It provides specialized tools such as fixture management for rendering charts in isolated DOM environments, mock contexts to control canvas behavior, and custom Jasmine matchers like `toEqualImageData` and `toEqualOptions` for asserting chart rendering and configuration. The package is currently at v0.5.0, with releases typically driven by dependency updates or minor feature enhancements rather than a strict schedule. Its primary differentiator is its deep integration with Chart.js's internal rendering and configuration, making it indispensable for maintaining visual and functional correctness across Chart.js ecosystem projects, particularly when used with Karma and Jasmine.
npm install chartjs-test-utilsVerified import paths — ran on the pinned version, not inferred.
Demonstrates setting up a basic Chart.js test using `fixture` to manage the DOM and `triggerMouseEvent` to simulate user interactions, within a Jasmine test suite.
Review existing `toEqualImageData` assertions and update expected baseline images or adjust chart dimensions to match new verification criteria. Ensure your charts render with consistent sizes.
Refactor tests to use `async/await` syntax when calling `triggerMouseEvent` and `fixture.run`. For example, change `fixture.run(element, cb)` to `await fixture.run(element)`.
Always ensure your project's `package.json` explicitly lists and installs compatible versions of `jasmine`, `karma`, and `karma-jasmine` as specified by `chartjs-test-utils`'s peer dependency requirements (e.g., `jasmine: >=3.0.0`, `karma: >=6.0.0`, `karma-jasmine: >=4.0.0`). Regularly check for updates and potential conflicts.
Add `fixture.cleanup();` to your test suite's `afterEach` block to correctly reset the DOM state after each test.
Ensure `chartjs-test-utils` is imported or required in a way that allows its matchers to be registered, typically by including `import 'chartjs-test-utils'` at the top of your test file or through a global setup in Karma/Jasmine.
Prepend `await` to calls to `triggerMouseEvent` and `fixture.run`. If the test function itself is not `async`, change its declaration to `it('should do something', async () => { ... });`.Run `npm install chartjs-test-utils` or `yarn add chartjs-test-utils` to ensure the package is correctly installed.