🧪 [testing improvement] Add unit tests for updateOptions#13
Conversation
Co-authored-by: jsem-nerad <88319121+jsem-nerad@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR adds a lightweight Node-based test harness and a minimal browser mock to unit test DotWave.prototype.updateOptions without requiring a real browser environment, improving confidence in runtime option updates.
Changes:
- Added
tests/mock-browser.jsto stub enough DOM/Canvas APIs forsrc/dotwave.jsto load under Node. - Added
tests/updateOptions.test.jswith unit tests covering option merging and conditional dot recreation whennumDots,dotStretch, orrotSmoothingchange.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/mock-browser.js | Introduces a basic DOM/window/canvas mock so DotWave can be constructed in Node tests. |
| tests/updateOptions.test.js | Adds a small test runner and unit tests validating updateOptions merge behavior and _createDots() invocation conditions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class MockElement { | ||
| constructor(tagName) { |
| querySelector: (selector) => { | ||
| if (selector === 'body') return new MockElement('body'); | ||
| return new MockElement('div'); | ||
| }, |
| const assert = require('assert'); | ||
| // In node environment, the IIFE attaches DotWave to 'global' if window is not defined. | ||
| // Wait, our mock defines global.window, so it attaches to window. | ||
| const DotWave = global.window.DotWave; |
| test('updateOptions should merge simple options', () => { | ||
| dotwave.updateOptions({ dotColor: 'red', numDots: 100 }); | ||
| assert.strictEqual(dotwave.options.dotColor, 'red'); | ||
| assert.strictEqual(dotwave.options.numDots, 100); | ||
| // Original default shouldn't change if not specified | ||
| assert.strictEqual(dotwave.options.backgroundColor, 'black'); | ||
| }); |
🎯 What: The testing gap addressed
The
updateOptionsmethod insrc/dotwave.jswas previously untested. This PR adds unit tests to verify its core logic, ensuring that basic object merging works as expected and thatthis._createDots()is conditionally invoked when specific configuration options change (numDots,dotStretch,rotSmoothing).📊 Coverage: What scenarios are now tested
updateOptions.numDotschanges.dotStretchchanges.rotSmoothingchanges.dotColor,friction).✨ Result: The improvement in test coverage
Introduced a mock browser setup (
tests/mock-browser.js) and a vanilla Node.js test runner (tests/updateOptions.test.js) that safely isolates side-effects to execute standalone JS test files. Test coverage has increased, helping guarantee stability forDotWave's reactive runtime modifications.PR created automatically by Jules for task 16837735816644289367 started by @jsem-nerad