Load the supplied module synchronously using require(), replacing any of the referenced modules with the mocks provided.
require()
Only works with CommonJS modules.
For type info, cast using as typeof import(...) or use the type parameter, as TypeScript lacks a way to infer imports dynamically.
as typeof import(...)
For example:
const myThing = t.mockRequire< typeof import('../my-thing.js')>('../my-thing.js', { some: { tricky: 'mocks' },}) Copy
const myThing = t.mockRequire< typeof import('../my-thing.js')>('../my-thing.js', { some: { tricky: 'mocks' },})
Optional
Load the supplied module synchronously using
require()
, replacing any of the referenced modules with the mocks provided.Only works with CommonJS modules.
For type info, cast using
as typeof import(...)
or use the type parameter, as TypeScript lacks a way to infer imports dynamically.For example: