Skip to content

possible to replace subset of exports from module? #536

@tony-kerz

Description

@tony-kerz

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')
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions