Skip to content

test: add unit tests for compare, math, case, condition, and repeat helpers#126

Merged
alondmnt merged 2 commits intojoplin:masterfrom
Jitmisra:test/add-helper-unit-tests
Mar 12, 2026
Merged

test: add unit tests for compare, math, case, condition, and repeat helpers#126
alondmnt merged 2 commits intojoplin:masterfrom
Jitmisra:test/add-helper-unit-tests

Conversation

@Jitmisra
Copy link
Copy Markdown
Contributor

PR Description:

Summary

Adds 52 dedicated unit tests for all 5 Handlebars helpers that previously had zero isolated test coverage. This directly addresses #80.

Tests Added

Helper Tests What's Covered
compare 12 All 8 operators (==, ===, !=, !==, <, <=, >, >=), all 16 named aliases (eq, equals, seq, strictly-equals, ne, not-equals, sne, strictly-not-equals, lt, less-than, lte, less-than-equals, gt, greater-than, gte, greater-than-equals), type coercion behavior, string lexicographic comparison, null/undefined handling, invalid operator error
condition 10 &&/and, ||/or, !/not operators with aliases, truthy/falsy coercion (0, "", null), combined usage with compare helper, invalid operator error
math 14 All 6 operators (+, -, *, /, **, %), modulo-by-zero error, division-by-zero → Infinity, floating point, negative numbers, string-to-number parsing, non-numeric input error, nested math operations, invalid operator error
case 7 upper/lower conversion, mixed case inputs, empty strings, numeric inputs, invalid type error
repeat 9 Basic repetition, repeat_index variable, 1-based indexing with math, zero count, negative count, single repeat, dynamic count, non-numeric error, context variable preservation

Approach

  • Tests register helpers via HelperFactory.registerHelpers() in beforeAll
  • Each test compiles a Handlebars template string and asserts the rendered output
  • Error cases use expect().toThrow() to validate proper error messages
  • Edge cases cover truthy/falsy coercion, type coercion, null/undefined, string comparison, and combined nested helpers

Results

  • Before: 46 tests across 4 test suites
  • After: 98 tests across 5 test suites (52 new tests, 0 failures)

File Changed

  • tests/helpers/helpers.spec.tsnew file (342 lines)

Copy link
Copy Markdown
Collaborator

@alondmnt alondmnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Jitmisra! I'll just replace single quotes with double quotes for eslint and merge this.

@alondmnt alondmnt merged commit 539901f into joplin:master Mar 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants