fix(curriculum): more fetch in failing tests (#59099)

This commit is contained in:
Oliver Eyton-Williams 2025-03-03 11:39:35 +01:00 committed by GitHub
parent 4e05e492db
commit 3addfc06a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 186 additions and 0 deletions

View File

@ -21,6 +21,12 @@ fetch("url-goes-here")
Make a `GET` request to this URL: `"https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json"`. Don't terminate your code with a semicolon yet.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use the `fetch()` method to make a `GET` request to `"https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json"`.

View File

@ -22,6 +22,12 @@ Chain the `.then()` method to your `fetch` call. Inside the `.then()` method, ad
Again, don't terminate the code with a semicolon yet.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use the `fetch()` method to make a `GET` request to `"https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json"`.

View File

@ -11,6 +11,12 @@ The data you get from a `GET` request is not usable at first. To make the data u
Remove `console.log(res)` and implicitly return `res.json()` instead.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should remove the `console.log(res)`.

View File

@ -12,6 +12,12 @@ In order to start working with the data, you will need to use another `.then()`
Chain another `.then()` to the existing `.then()` method. This time, pass in `data` as the parameter for the callback function. For the callback, use a curly brace because you will have more than one expression. Within your callback function, log `data` to the console to see what it looks like.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use the `fetch()` method to make a `GET` request to `"https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json"`.

View File

@ -13,6 +13,12 @@ Chain `.catch()` to the last `.then()`. Pass in a callback function with `err` a
**Note**: `catch` is the last call chained on to fetch, so you can terminate your code with a semicolon.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use the `fetch()` method to make a `GET` request to `"https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json"`.

View File

@ -13,6 +13,12 @@ Instead, you should add 8 authors at a time, and have a button to add 8 more unt
Use `let` to create 2 variables named `startingIndex` and `endingIndex`, and assign them the number values `0` and `8`, respectively. Also, create an `authorDataArr` variable with `let` and set it to an empty array.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use `let` to declare a variable named `startingIndex`.

View File

@ -11,6 +11,12 @@ Now you'll create a function to populate the UI with the author data. You will c
Create an empty arrow function named `displayAuthors` that takes `authors` as a parameter.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use `const` to create an empty function named `displayAuthors`.

View File

@ -9,6 +9,12 @@ dashedName: step-9
Inside your `displayAuthors` function, chain `.forEach()` to `authors`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should chain `.forEach()` to `authors`.

View File

@ -11,6 +11,12 @@ Pass an empty callback function to the `.forEach()` method. For the first parame
For the second parameter, pass in `index`. This will represent the position of each author, and will be useful for pagination later.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should destructure `author`, `image`, `url`, and `bio` as the first parameter of your callback function. Don't forget to put them inside curly braces.

View File

@ -12,6 +12,12 @@ Now it's time to start building the HTML for the page with your destructured dat
Inside your callback function, use the compound assignment operator to append an empty template literal to the `innerHTML` of `authorContainer`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should access the `innerHTML` of `authorContainer`.

View File

@ -11,6 +11,12 @@ Inside the template literal, create a `div` element with the `id` set to the `in
Also, add a `class` of `"user-card"` to the `div`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create a `div` element with the class `"user-card"`.

View File

@ -12,6 +12,12 @@ Now you need to show some information about the author. First, show the author's
Create an `h2` tag with the `class` `"author-name"`. Then, interpolate `author` inside the `h2` tag. This is the author's name.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create an `h2` element within your `div` element.

View File

@ -11,6 +11,12 @@ To see the authors' names on the page, you need to call the `displayAuthors` fun
First, remove your `console.log()` statement. Then, assign `data` to the `authorDataArr` variable.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should remove the console log showing the `data`.

View File

@ -11,6 +11,12 @@ Now `authorDataArr` is the same as the `data` you logged to the console a while
Inside your `console.log()` statement, add the text `"Author Data Array:"` as the first argument and `authorDataArr` as the second argument. Use comma to separate the text from `authorDataArr`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should assign `data` to the `authorDataArr` variable

View File

@ -11,6 +11,12 @@ Now it's time to call the `displayAuthors` function. But again, you don't want t
First, remove the console log statement showing `authorDataArr`. Then, call the `displayAuthors` function with the `authorDataArr` array and `.slice()`. Use the `startingIndex` variable for the starting point and the `endingIndex` variable for the ending point.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should assign `data` to the `authorDataArr` variable

View File

@ -15,6 +15,12 @@ Now create an image tag and give it the `class` `"user-img"`. Use string interpo
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create an `img` element.

View File

@ -17,6 +17,12 @@ Add a paragraph element with the `class` `"bio"`, then interpolate `bio` inside
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create a `p` element.

View File

@ -17,6 +17,12 @@ Add an anchor element with the `class` `"author-link"`, interpolate `url` as the
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create an anchor element.

View File

@ -11,6 +11,12 @@ Now you have everything you want to include in the UI. The next step is to make
Create a `fetchMoreAuthors` function with the arrow function syntax. Don't put anything in it yet. Make sure you use curly braces because you'll have more than one expression inside the function.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use `const` to create a `fetchMoreAuthors` function.

View File

@ -9,6 +9,12 @@ dashedName: step-21
Inside the `fetchMoreAuthors` function, set the `startingIndex` and `endingIndex` variables to `+= 8` each.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should set the `startingIndex` variable to `+=8`.

View File

@ -11,6 +11,12 @@ Now call the `displayAuthors` function with a portion of the author data just li
If you click the `Load More Authors` button after calling the function, it won't work. That's because you still have to add the `click` event listener to the button. You'll do that next.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should call your `displayAuthors` function.

View File

@ -13,6 +13,12 @@ Use `addEventListener` to add a `"click"` event listener to `loadMoreBtn`. Also,
After that, when you click the button you should see 8 more authors.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should call the `addEventListener()` method on your `loadMoreBtn` variable.

View File

@ -13,6 +13,12 @@ First, if you click the `Load More Authors` button a couple of times, you'll see
Inside the `fetchMoreAuthors` function, write an `if` statement and set the condition to `authorDataArr.length <= endingIndex` meaning there's no more data to load.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should have an `if` statement.

View File

@ -9,6 +9,12 @@ dashedName: step-25
If this condition is met, disable the button by setting its `disabled` property to `true`. Also, set the `textContent` of the button to `"No more data to load"`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should set the `disabled` property of `loadMoreBtn` to `true`.

View File

@ -17,6 +17,12 @@ Add a `div` element above the author's bio and give it the `class` `"purple-divi
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create a `div` element before your `p` element.

View File

@ -11,6 +11,12 @@ Some of the author bios are much longer than others. To give the cards a uniform
Within the paragraph element, replace `bio` with a ternary operator. For the condition, check if the length of `bio` is greater than 50. If it is, use the `.slice()` method to extract the first 50 characters of `bio` and add an ellipsis at the end. Otherwise, show the full `bio`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create a `p` element.

View File

@ -11,6 +11,12 @@ Finally, what if there's an error and the author data fail to load? Then we need
Inside the `.catch()`, remove the `console.error()` and set the `innerHTML` of the `authorContainer` to a `p` element with the `class` `"error-msg"` and text `"There was an error loading the authors"`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should remove your `console.error` and its text.

View File

@ -13,6 +13,12 @@ Access the `style` property of the `Load More Authors` button and set `cursor` t
With that, your author page is complete!
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should access the `style` property of `loadMoreBtn` with a dot notation.

View File

@ -17,6 +17,12 @@ fetch("url-goes-here")
Make a `GET` request to this URL: `"https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json"`. Don't terminate your code with a semicolon yet.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should use the `fetch()` method to make a `GET` request to `"https://cdn.freecodecamp.org/curriculum/news-author-page/authors.json"`.

View File

@ -11,6 +11,12 @@ Now it's time to call the `displayAuthors` function. But again, you don't want t
First, remove the console log statement showing `authorDataArr`. Then, call the `displayAuthors` function with the `authorDataArr` array and `.slice()`. Use the `startingIndex` variable for the starting point and the `endingIndex` variable for the ending point.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should assign `data` to the `authorDataArr` variable

View File

@ -11,6 +11,12 @@ Some of the author bios are much longer than others. To give the cards a uniform
Within the paragraph element, replace `bio` with a ternary operator. For the condition, check if the length of `bio` is greater than 50. If it is, use the `.slice()` method to extract the first 50 characters of `bio` and add an ellipsis at the end. Otherwise, show the full `bio`.
# --before-all--
```js
window.fetch = () => Promise.resolve({json: () => Promise.resolve([{ author: 'Whoever', image: 'http://not-a-real-url.nowhere/no-image.jpg', url: "http://not-a-real-url.nowhere/", bio: 'words go here' }])});
```
# --hints--
You should create a `p` element.