Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Nov 2, 2025. It is now read-only.
Adds t.mock() API - #25
Merged
Merged
Conversation
This brings into **tap** the standard mocking system we have been using across the ecosystem of packages from the npm cli which consists into hijacking the `require` calls from a given module and defining whatever mock we want via something as simple as a key/value object. It's a very conscious decision to make it a very opinionated API, as stated in https://github.com/tapjs/node-tap#tutti-i-gusti-sono-gusti - focusing only on the pattern that have been the standard way we handle mocks. It builds on the initial draft work from @nlf (ref: https://gist.github.com/nlf/52ca6adab49e5b3939ba37c7f0fc51c6) and initial brainstorming of such an API with @mikemimik - thanks ❤️ Example: ```js t.test('testing something, t => { const myModule = t.mock('../my-module.js', { fs: { readFileSync: () => 'foo' } }) t.equal(myModule.bar(), 'foo', 'should receive expected content') }) ``` Credit: @ruyadorno, @nlf Reviewed-by: @isaacs PR-URL: tapjs/tapjs#698Closes: tapjs/tapjs#698
isaacsforce-pushed
the
isaacs/add-mock-api
branch
from
February 16, 2021 05:39
df2708f to
1e9ff26Comparecoreyfarrell
approved these changes
Feb 16, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 brings into tap the standard mocking system we have been using
across the ecosystem of packages from the npm cli which consists into
hijacking the
requirecalls from a given module and defining whatevermock we want via something as simple as a key/value object.
It's a very conscious decision to make it a very opinionated API, as
stated in https://github.com/tapjs/node-tap#tutti-i-gusti-sono-gusti -
focusing only on the pattern that have been the standard way we handle
mocks.
It builds on the initial draft work from @nlf (ref:
https://gist.github.com/nlf/52ca6adab49e5b3939ba37c7f0fc51c6) and
initial brainstorming of such an API with @mikemimik - thanks ❤️
Example:
Credit: @ruyadorno, @nlf
Reviewed-by: @isaacs
PR-URL: tapjs/tapjs#698
Closes: tapjs/tapjs#698