Incorrect documentation example (partial mocking)
Hi, I'm trying to replicate the example in the partial mocking documentation, but the test fails because it doesn't override the implementation. VSCode also detects that the
spy()
function should only receive two arguments. How can i fix or do partial mocking?
Thanks
- jsr:@std/testing/mock 1.0.12
- deno 2.3.1
- linux mint 22.1
ref: https://docs.deno.com/examples/mocking_tutorial/#partial-mockingDeno
Testing in isolation with mocks
Master the art of mocking in your unit tests. Learn how spies, stubs, fake time, and other Deno tools let you improve your code and confidence

6 Replies
I'm still stuck, do you know how I could do partial mocking?
Sorry for the confusion. The above example looks wrong to me. If you need to replace the implementation of method, you need to use
stub
function from @std/testing/mock
:
See also the docs in JSR https://jsr.io/@std/testing/doc/mock
JSR
mock - @std/testing - JSR
@std/testing on JSR: Tools for testing Deno code like snapshot testing, bdd testing, and time mocking
I'm trying to fix the docs above https://github.com/denoland/docs/pull/1766
GitHub
fix some mock tutorial examples by kt3k · Pull Request #1766 · de...
This PR fixes 2 examples in examples/mocking_tutorial page.
Thanks @kt3k for the clarification, is there any plan for the 'spy()' function to replace the implementations?
Spy is just for observing without replacing the original. Stub is for observing and replacing the original. Stub is an extension of Spy.
All the assertSpy functions work with stubs.
If spy could replace the original function there would be no difference between spy and stub.