sinonjs / sinonjs/sinon

Elaborate on "For the stubbing to work, the stubbed method cannot be destructured, neither in the module under test nor in the test."

Open
#2,552 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
9.8k
Forks
809
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
The How to stub a dependency of a module documentation says:

To stub a dependency (imported module) of a module under test you have to import it explicitly in your test and stub the desired method. For the stubbing to work, the stubbed method cannot be destructured, neither in the module under test nor in the test.

I'm not really sure what this bold part means. Does it mean you can't destructure the import statement? If so, while I have found that to be true in the test file, I haven't found that the be true in the module under test. That makes me think I'm either:

  1. Misunderstanding what this sentence means.
  2. Reading out of date documentation.

Describe the solution you'd like
I'd like this sentence to be rewritten or expanded upon to clarify. If possible, an example would go a long way.

Describe alternatives you've considered

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read docs/_howto/stub-dependency.md and the linked MDN destructuring explanation first. Clarify what “destructured” means in the stubbing guidance, adding an example if the existing documentation supports one. Done means the sentence clearly explains the constraint and its effect in both the test and module under test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.