testdouble / testdouble/testdouble.js

add `withContext` option

Open
#207 0 comments 3 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

Proposal: allow test double stubbing/verification configuration to specify the value of this that's bound when the test double function is called.

td.when(myTd(), {withContext: window})).thenReturn(5)

myTd() // undefined
myTd.bind(window)() // 5

And for verify:

myTd()
td.verify(myTd(), {withContext: window})) // blows up

myTd.bind(window)()
td.verify(myTd(), {withContext: window})) // passes

Also, argument matchers should be supported:

myTd.bind(new Promise())()
td.verify(myTd(), {withContext: td.matchers.argThat(arg => arg instanceof Promise)})) // passes

Thoughts?

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 reading the existing td.when and td.verify behavior, then inspect how argument matchers are handled. The change is done when stubbing and verification can match the bound this value through withContext, including matcher support for the context object, with tests covering the examples in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.