Skip to content
This repository was archived by the owner on Feb 10, 2022. It is now read-only.

Fix promise tests language #34

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ describe("exercise 1", () => {
🛠️ requestSalePrice takes a sku.
🛠️ call fetchProduct with the sku argument
🛠️ and handle the following cases:
🛠️ 1. If requestSalePrice responds with a product object
🛠️ 1. If fetchProduct responds with a product object
🛠️ that contains a salePrice field, return the sale price.
🛠️ 2. If requestSalePrice doesn't respond with a
🛠️ 2. If fetchProduct doesn't respond with a
🛠️ product object that contains a salePrice field,
🛠️ throw a new Error with the string
🛠️ "Your product is not on sale"
🛠️ 2. If requestSalePrice doesn't respond with
🛠️ 2. If fetchProduct doesn't respond with
🛠️ a product at all (response is null) throw a new Error
🛠️ with the string "Your request didn't return a product"
🛠️ 3. Catch and return any errors
Expand All @@ -94,13 +94,13 @@ function requestSalePrice(sku) {
}

describe("exercise 2", () => {
it("Calls requestSalePrice and returns products", () => {
it("Calls requestSalePrice and returns product's sale price", () => {
return requestSalePrice("SEHO2194").then(response => {
expect(response).toEqual(data["SEHO2194"].salePrice);
});
});

it("Calls requestSalePrice with an endpoint that responds with no sale price and throws the error 'Your request didn't return a product'", () => {
it("Calls requestSalePrice with an endpoint that responds with no sale price and throws the error 'Your product is not on sale'", () => {
const err = new Error("Your product is not on sale");
expect.assertions(1);
return expect(requestSalePrice("RIGH2345")).resolves.toEqual(err);
Expand All @@ -112,13 +112,13 @@ describe("exercise 2", () => {
return expect(requestSalePrice("DRTG1100")).resolves.toEqual(err);
});

it("Null response", () => {
it("Calls requestSalePrice with an endpoint that returns a null response for product", () => {
const err = new Error("Your request didn't return a product");
expect.assertions(1);
return expect(requestSalePrice("NOPR0000")).resolves.toEqual(err);
});

it("Errors on the server", () => {
it("Calls requestSalePrice with an endpoint that gives errors on the server", () => {
const err = new Error("Error loading file");
expect.assertions(1);
return expect(requestSalePrice("DRTG1100")).resolves.toEqual(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import fetchBasket from "../../api/baskets";
Welcome to Async Js- Intro to promises!

This will build your knowledge of async JS -
particularly promises. You will use to two mock APIs
particularly promises. You will use two mock APIs
to mimic working with something like a fetch or AJAX call.

If you are curious about those fake APIs, feel free to
Expand All @@ -30,7 +30,7 @@ const exerciseOne = () => {
// Your code here
};

test('the promise resolves with a string of "promise complete!"', () => {
test('the promise resolves with a string "promise complete!"', () => {
return expect(exerciseOne()).resolves.toBe("promise complete!");
});

Expand All @@ -46,7 +46,7 @@ const exerciseTwo = () => {
// Your code here
};

test('the promise rejects with a string of "promise rejected!"', () => {
test('the promise rejects with a string "promise rejected!"', () => {
expect.assertions(1);
return expect(exerciseTwo()).rejects.toMatch("promise rejected!");
});
Expand Down Expand Up @@ -131,8 +131,9 @@ test("getBasketId returns empty string when no basket id exists", () => {
🛠️ Fill in the getBasketItems function below
🛠️ It should take in a basketId string,
🛠️ call the fetchBasket endpoint with basketId.
🛠️ If items exists on the response object, resolve with the items array.
🛠️ If items doesn't exist on the response object, resolve with an empty array
🛠️ If basket with given id does not exists, reject with string 'Invalid basket ID passed'.
🛠️ If items exist on the response object, resolve with the items array.
🛠️ If items don't exist on the response object, resolve with an empty array

💡 fetchBasket returns an object in this shape:
{
Expand Down