top | item 27645887

(no title)

cfrover | 4 years ago

In the javascript world, we have test frameworks like jest which provide mocking implementations. How does `spy` (also a JS/TS lib) compare with Jest? - https://jestjs.io/docs/mock-function-api

discuss

order

sayan51|4 years ago

Good question! I am not a user of Jest. So can't really comment on that. Taking a look at the docs from jest, it seems to me that my spy API is far more straightforward. Also it can be used by itself. Theoretically it can also be used without unit testing. It happens to be the case that spy is used generally in tests. Another point to note is that the implementation is not tied to any test framework.

sayan51|4 years ago

In my projects things are arranged in terms of class, and dependencies are injected to constructor using dependency injection. Then the requirements of mocking the dependencies during unit tests bolis down to mocking parts or whole of the implementation as well as recording those method cqlls. The spy implementation is based on that philosophy and is therefore simple, straightforward and tiny.