-
-
Save taylorjdawson/bb3357725081930cdc6c261edcf01a86 to your computer and use it in GitHub Desktop.
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
import fetch, {Headers} from 'node-fetch'; | |
import ky from 'ky'; | |
global.window = {}; | |
global.window.fetch = fetch; | |
global.window.Headers = Headers; | |
let url_short_json_response = 'https://jsonplaceholder.typicode.com/users'; // 10 users | |
let url_long_json_response = 'https://jsonplaceholder.typicode.com/comments'; // 500 comments | |
// This will work | |
(async () => { | |
const json = await ky(url_short_json_response); | |
console.log('✔️ url_short vanilla'); | |
})(); | |
// This will work | |
(async () => { | |
const json = await ky(url_short_json_response).json(); | |
console.log('✔️ url_short with .json()'); | |
})(); | |
// This will work | |
(async () => { | |
const json = await ky(url_short_json_response).json(); | |
console.log('✔️ url_short with .text()'); | |
})(); | |
// This will work | |
(async () => { | |
const json = await ky(url_long_json_response); | |
console.log('✔️ url_long vanila'); | |
})(); | |
// !!!!This will not work!!!! | |
(async () => { | |
const json = await ky(url_long_json_response, {retry: 0}).json(); | |
console.log('✔️ url_long with .json() (this will not be displayed)'); | |
})(); | |
// !!!!This will not work!!!! | |
(async () => { | |
const json = await ky(url_long_json_response, {retry: 0}).text(); | |
console.log('✔️ url_long with .text() (this will not be displayed)'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment