Mocking named TypeScript imports during tests

1 · Gleb Bahmutov · May 20, 2020, 2:23 p.m.
Note: you can find the companion source code in bahmutov/mock-ts-imports repository.Imagine we have the following 2 TypeScript files.math.ts12export const add = (a, b) => a + bexport const sub = (a, b) => a - buser.ts12import { add } from './math'export const compute = (a, b) => add(a, b)Both files use named imports and exports which causes problems trying to stub them from the tests.Testing direct named importLet's write unit test to confirm the function add works. I will use Ava test runner. T...