testdouble / testdouble/testdouble.js

Multiple stubbings with throwException causes unexpected behavior

Open
#537 1 comment 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

When you set two stubbings that match the same invocation with the first stubbing calling throwException declaring the second stubbing trigger the exception of the first stubbing.

Example :

td.when(dep()).thenThrow(new Error())
td.when(dep()).thenReturn(true)

Executing the above code will throw an error of type Error.

I think it relates to this issue. Not sure if it can be fixed in testdouble but is there at least a workaround ?

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 reproducing the two-stubbing example in the issue and review the related issue #180. Trace how matching stubbings are selected when the first uses thenThrow and the second uses thenReturn. Done means the observed behavior is resolved or a verified workaround is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing
Issue type
Bug
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.