Sinon stub functions that are exported through an index file

Viewed 95

Consider the following typescript files:

  • A.ts
export const funcA = ()=>{}
  • B.ts
export const funcB = ()=>{}
  • index.ts
export * from './A.ts'
export * from './B.ts'

Now in my tests, if I import the inner file directly, I am able to mock its members:

import * as A from './A.ts'
sinon.stub(A,'funcA');

However, if I import the index, it won't let me mock its members:

import * as myModule from `./index.ts`
sinon.stub(myModule,'funcA'); // does not work

Can someone explain? Is there a different approach?

0 Answers
Related