Elektrine lite

← Feed

@Tamo240@programming.dev

2026-01-30 19:37 UTC

While my experience is mostly C++, I assume these mocking libraries are similar in allowing you to create a class that can report it's own usage, and allow for arbitrary returns values and side effects, which is incredibly useful, especially in conjunction with dependency injection. What ```patch``` lets you do is directly overwrite the functionality of private member functions on the fly, which if Java/JavaScript can do I'd love to know, I thought this was a uniquely Pythonic magic.

Replies (2)

  • @jjjalljs@ttrpg.network 2026-01-31 01:09

    Javascript has mocking with jest: https://jestjs.io/docs/mock-functions There's an example there of mocking our axios (a common library for network requests, a la python requests) It's been a long time since I've used java, but mockito exists: https://site.mockito.org/javadoc/current/org/mockito/Mockito.html#2 (Usage note for anyone unfamiliar, but despite the name java and JavaScript are radically different languages.)

    Open ##2753396

  • @SlurpingPus@lemmy.world 2026-01-31 11:35

    JS is also just as dynamic in this regard. Both JS and Python create and modify objects at runtime and use object fields instead of static definitions of methods or properties. It's probably inherited from Smalltalk.

    Open ##2753397