testdouble / testdouble/testdouble.js

possible to replace subset of exports from module?

Open
#536 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

sample.js

export {a, b}

function a() {
  return b()
}

function b() {
  return 'b'
}

want to replace b() but preserve a()...

td.test.js

import test from 'ava'
import * as td from 'testdouble'
// import {a} from './sample.js'

let mock

test.beforeEach(async () => {
  // unclear how to use second parameter here, is this a potential solution?
  // or is the ask not supported and would need to place `a` and `b` in separate files?
  //
  mock = await td.replaceEsm('./sample.js')
})

test.afterEach(async () => {
  td.reset()
})

test('a', (t) => {
  td.when(mock.b()).thenResolve('bee')
  t.is(mock.a(), 'bee')
})

test('b', (t) => {
  td.when(mock.b()).thenReturn('be')
  t.is(mock.b(), 'be')
})

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 with td.test.js and the replaceEsm entry point to determine whether partial export replacement is supported. Use sample.js as the fixture and make the test demonstrate preserving a while replacing b; done means both assertions pass without moving the functions.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.