testdouble / testdouble/testdouble.js

Feature request: `td.func().reset()` (reset spy/stub state)

Open
#529 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.4k
Forks
140
Avg merge
22h
Merged PRs (30d)
1

Description

In many cases, spies are re-useable, so they can be set up at the root of the test.

When asserting cases where a spy may or may not have been called, the spy's state needs to be re-set between cases (via afterEach).

At current, it seems the only way to effectively re-set a testdouble spy/stub's state is to overwrite the whole thing with a fresh spy, which creates a daisy-chain of make-work: that spy is likely being fed into a module replacement, so now the module has to be needlessly replaced every time the spy/stub is re-set.

Contributor guide

No contributing guide indexed for this repository

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

Start by locating the spy and stub state-management code and the existing tests for reusable doubles. Confirm how state is currently replaced, then add coverage for resetting a double in place so its call history and stub state are cleared without replacing the dependent module.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.