Please enable JavaScript.
Coggle requires JavaScript to display documents.
Jest Mock Functions - Coggle Diagram
Jest Mock Functions
when to use
when you want to test a function, that has dependencies
-
-
-
how to use
mocking a function
usage: assign a dependency, into a jest.fn(), then test its interaction with that dependency
-
mocking a module
similar to mocking a function, but assign a WHOLE function in a module into a mock function automatically
spy a function
motivation
since mocking replaces implementation, sometimes you want to switch between a mock & actual implementation / revert it
similar to copy a mock into a variable, but keep the original one / don't mutate the original one
use case
testing how a function interacts with a dependency, as well as getting the actual return / implementation of the dependency
mock types
-
spyOn mocking
keep the function's logics,
but "spy" on their behaviors
-
spy if they returns this, or that
-
-
-
purpose
"testing how a function, interacts with its dependency/ies"
-
-
-