feat: Add FetchMocker#mockObject() method to mock non-global fetch #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces new functionality to mock the
fetch
function on specific objects, enhancing the flexibility of theFetchMocker
class. The most important changes include updates to the documentation, the addition of new methods to theFetchMocker
class, and corresponding tests.Enhancements to
FetchMocker
functionality:src/fetch-mocker.js
: AddedmockObject
andunmockObject
methods to allow mocking and unmocking thefetch
function on specific objects. These methods store the original fetch functions in aWeakMap
and replace them with the mocked fetch function.Documentation updates:
docs/src/content/docs/fetch-mockers/creating-fetch-mocker.mdx
: Updated documentation to include examples and explanations of how to use the newmockObject
andunmockObject
methods to mock thefetch
function on specific objects.Testing updates:
tests/fetch-mocker.test.js
: Added tests for the newmockObject
andunmockObject
methods, verifying their functionality, including handling custom property names and restoring multiple mocked properties.Codebase adjustments:
src/fetch-mocker.js
: Updated themockGlobal
andunmockGlobal
methods to use the newmockObject
andunmockObject
methods for consistency and code reuse.src/fetch-mocker.js
: Changed the documentation comment for thefetch
property to reflect that it is the created fetch function, not the global fetch function.