#2031·PrivateBin

Properly make use of stubs/a mocking (& assertion) framework for testing JS

Author: rugkCreated Sep 25, 2026Updated Sep 25, 2026
Labelsenhancementcode qualityjavascript

The problem

  • a lot of our modules depend on each other
  • they have quite complex relationships
  • for tests like the Controller, we have huge HTML dependencies (aka like a big DOM)
    • each logic change potentially affects this HTML and needs adjustments in many tests, even if unrelated
    • That said, I consider some HTML/DOM-based tests useful as they are more like integration tests. Testing all modules together and e.g. that everything loads correctly in the browser then is alos useful.

The solution

  • using a proper stubbing/mocking framework that also allows to check whether
  • https://jasmine.github.io/ can do this, but also offers it's own assertions (though maybe we do want that anyway? NodeJS assert is really limited) - though we currently use mocha, jasmine "just" has everything built-in
  • So if we want to keep using mocha, assertion frameworks for it (despite NodeJS way too simple one) exist: https://www.chaijs.com/ is quite popular, maybe
    • as far as I see mocking and assertion frameworks usually are bundled together, because the data of the mocks/stubs needs to be recorded somewhere
    • see more options: https://mochajs.org/features/assertions/

Alternatives

Additional context

The LLM "invented" it here, e.g.: https://github.com/PrivateBin/PrivateBin/pull/1971/changes?w=1#diff-3620214617aab1d3dd4f4ff000a8364cb8181f24fb79bafd9d5d8097d452c2c1R12

This is the most basic JS-native implementation, but not quite useful and doe snot scale.

Related:

  • #1336