mirror of https://github.com/nodejs/node.git
21 lines
482 B
JavaScript
21 lines
482 B
JavaScript
'use strict';
|
|
require('../common');
|
|
const { mock, test } = require('node:test');
|
|
const assert = require('node:assert');
|
|
|
|
test('should correctly stub globalThis.fetch', async () => {
|
|
const customFetch = async (url) => {
|
|
return {
|
|
text: async () => 'foo',
|
|
};
|
|
};
|
|
|
|
mock.method(globalThis, 'fetch', customFetch);
|
|
|
|
const response = await globalThis.fetch('some-url');
|
|
const text = await response.text();
|
|
|
|
assert.strictEqual(text, 'foo');
|
|
mock.restoreAll();
|
|
});
|