Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution/ronald ris with tests #30

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

ronaldris21
Copy link

For this solution I've adapted the exercises in order to have test for the solutions


describe("3. AsyncAwait:", () => {
it("74", async () => {
expect(await solution(74)).toEqual({

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use 'toStrictEqualto avoid allowing undefined properties of an object or array. Another alternative is usetoMatchObject` to only compare a set of properties of an object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be a better approach to use "toStrictEqual" on this tests. I'll change it.
Thx

Comment on lines 38 to 43
let resultsAll = await Promise.all([pricesAsync(id), productsAsync(id)]);
return {
id,
price: resultsAll[0],
product: resultsAll[1],
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can use destructuring here

Suggested change
let resultsAll = await Promise.all([pricesAsync(id), productsAsync(id)]);
return {
id,
price: resultsAll[0],
product: resultsAll[1],
};
let [price, product] = await Promise.all([pricesAsync(id), productsAsync(id)]);
return {
id,
price,
product,
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! promise.all returns directly the result values, so I really like this approach
I'll keep it mind

Comment on lines 64 to 69

return {
id,
price: resultsAllSettled[0].value,
product: resultsAllSettled[1].value,
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to be more clear in naming variables, we can use destructuring here

Suggested change
return {
id,
price: resultsAllSettled[0].value,
product: resultsAllSettled[1].value,
};
const [priceSettled, productSettled] = resultsAllSettled
return {
id,
price: priceSettled.value,
product: productSettled.value,
};

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for readability!
I've already applied this changes, and solved the gap it left after change the variable names.

I realized not all the solution methods have test, so I'll refractored the code too.

…allSettled, race, any)

Added separate tests for each Promise method (all, allSettled, race, any) in the asyncAwait exercise.

Fix(asyncAwait): applied PR recomendations
@ronaldris21
Copy link
Author

Tests take a long time to run (around 30 seconds).
I'll try to run each test asynchronous to improve testing performance

…each promise method (all, allsettled, any,race)

Performance improve at least 240%, being tests executed faster now
@juanmdpc
Copy link

Awesome job! Keep it up! 👊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants