-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: test for fetch mock without prior invocation
The purpose of this test is to verify the correct behavior of stubbing the globalThis.fetch method with custom implementation. It checks whether the stubbed fetch function correctly returns the expected response without calling fetch iteself first.
- Loading branch information
1 parent
5c6a889
commit 2eddeda
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
Check failure on line 1 in test/parallel/test-fetch-mock.js GitHub Actions / test-linux
Check failure on line 1 in test/parallel/test-fetch-mock.js GitHub Actions / test-asan
Check failure on line 1 in test/parallel/test-fetch-mock.js GitHub Actions / test-macOS
Check failure on line 1 in test/parallel/test-fetch-mock.js GitHub Actions / test-ubsan
|
||
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'); | ||
}); |