Skip to content

Instantly share code, notes, and snippets.

@taylorjdawson
Last active September 18, 2018 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taylorjdawson/bb3357725081930cdc6c261edcf01a86 to your computer and use it in GitHub Desktop.
Save taylorjdawson/bb3357725081930cdc6c261edcf01a86 to your computer and use it in GitHub Desktop.
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