mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
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();
|
||
|
});
|