Convenience method to create a mock from an existing object by overriding some (possibly deeply nested) methods or properties.
Example:
import * as fs from 'node:fs'const mockedThing = t.mockRequire('./module.js', t.createMock( { fs }, { fs: { statSync: myMockedStatSync }}) Copy
import * as fs from 'node:fs'const mockedThing = t.mockRequire('./module.js', t.createMock( { fs }, { fs: { statSync: myMockedStatSync }})
This can also appear anywhere in the object hierarchy, which may be more convenient in some cases:
import * as blah from '@long-name/blah-api'const mockedThing = t.mockRequire('./module.js', { fs: t.createMock(fs, { statSync: myMockedStatSync }), child_process: t.createMock(child_process, { spawn: mockSpawn }), '@long-name/blah-api': t.createMock(blah, { some: { nested: { prop: true } } })}) Copy
import * as blah from '@long-name/blah-api'const mockedThing = t.mockRequire('./module.js', { fs: t.createMock(fs, { statSync: myMockedStatSync }), child_process: t.createMock(child_process, { spawn: mockSpawn }), '@long-name/blah-api': t.createMock(blah, { some: { nested: { prop: true } } })})
To remove a property, set it as undefined in the override.
Convenience method to create a mock from an existing object by overriding some (possibly deeply nested) methods or properties.
Example:
This can also appear anywhere in the object hierarchy, which may be more convenient in some cases:
To remove a property, set it as undefined in the override.