Skip to content

Mocking Modules #47959

Answered by cjihrig
koddsson asked this question in General
May 11, 2023 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

You haven't provided a runnable example, so it's hard to say for sure. However, given the error message, it's possible you're trying to mock a method that is non-configurable:

import { test } from 'node:test';
const obj = Object.create(null);
Object.defineProperty(obj, 'foo', { value: function() {} });

test('test code', async (t) => {
  t.mock.method(obj, 'foo');
});

I can tell you that mocking of entire modules is not currently implemented. It's something I plan to work on once ESM loaders stabilize a bit more.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@koddsson
Comment options

@jasonwilliams
Comment options

@cjihrig
Comment options

@jasonwilliams
Comment options

Answer selected by koddsson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants