Skip to content

[Bug] Add Unit Tests for musicutils.js — Core Music Constants & Utilities Are Untested #6471

@swapnachoudhary43

Description

@swapnachoudhary43

Current Behavior

js/utils/musicutils.js is one of the most critical files in the entire MusicBlocks codebase — it contains all core music constants (SOLFEGENAMES, NOTENAMES, ALLNOTENAMES, scales, modes, etc.) and utility functions used across every other block file. Despite this, it currently has 0% unit test coverage.

This means:

  • Regressions in note/pitch/solfege data go completely undetected by CI
  • Contributors cannot safely refactor or extend music utility logic
  • Any changes to constants like SOLFEGENAMES1 or NOTENAMES risk breaking the entire app silently

Desired Situation

Create a new test file __tests__/utils/musicutils.test.js that covers the core exported constants and utility functions in musicutils.js, including:

  • NOTENAMES array contains exactly the 7 expected note letters (C, D, E, F, G, A, B)
  • SOLFEGENAMES1 array contains all 7 base solfege syllables (do, re, mi, fa, sol, la, ti)
  • ALLNOTENAMES array includes sharps, flats, double accidentals
  • Solfege names do not contain duplicates for base syllables
  • Pitch/note name arrays are non-empty and of correct type (Array of strings)
  • Boundary checks: first and last elements of NOTENAMES and SOLFEGENAMES1 are correct
  • Mode definitions (e.g. major, minor) exist and have correct step counts (7 steps)
  • Each mode's steps sum to 12 (one full octave of semitones)

Acceptance Criteria

  • A new file __tests__/utils/musicutils.test.js is created
  • All listed test cases pass with npm test
  • Coverage for musicutils.js increases meaningfully (target ≥ 60%)
  • No existing tests are broken
  • Code follows the project's existing Jest testing conventions (see docs/TESTING.md)

Additional Context

  • musicutils.js is 4,427 lines — the 3rd largest JS file in the codebase
  • It is imported/used by PitchBlocks.js, RhythmBlocks.js, MeterBlocks.js, IntervalsBlocks.js, and many widgets
  • A similar issue was opened for FlowBlocks.js (Add tests for FlowBlocks #4829) — this follows the same initiative but targets the foundational music utility layer
  • Maintainers have explicitly requested more unit tests in v3.6.2 release notes

Checklist

✅ I have read and followed the project's code of conduct.
✅ I have searched for similar issues before creating this one.
✅ I have provided all the necessary information to understand and reproduce the issue.
✅ I am willing to contribute to the resolution of this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions