-
Notifications
You must be signed in to change notification settings - Fork 26
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
base: master
Are you sure you want to change the base?
Solution/ronald ris with tests #30
Conversation
… passed the tests
3-async-await/asyncAwait.test.js
Outdated
|
||
describe("3. AsyncAwait:", () => { | ||
it("74", async () => { | ||
expect(await solution(74)).toEqual({ |
There was a problem hiding this comment.
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 use
toMatchObject` to only compare a set of properties of an object.
There was a problem hiding this comment.
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
3-async-await/solution.js
Outdated
let resultsAll = await Promise.all([pricesAsync(id), productsAsync(id)]); | ||
return { | ||
id, | ||
price: resultsAll[0], | ||
product: resultsAll[1], | ||
}; |
There was a problem hiding this comment.
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
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, | |
}; |
There was a problem hiding this comment.
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
3-async-await/solution.js
Outdated
|
||
return { | ||
id, | ||
price: resultsAllSettled[0].value, | ||
product: resultsAllSettled[1].value, | ||
}; |
There was a problem hiding this comment.
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
return { | |
id, | |
price: resultsAllSettled[0].value, | |
product: resultsAllSettled[1].value, | |
}; | |
const [priceSettled, productSettled] = resultsAllSettled | |
return { | |
id, | |
price: priceSettled.value, | |
product: productSettled.value, | |
}; |
There was a problem hiding this comment.
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
Tests take a long time to run (around 30 seconds). |
…each promise method (all, allsettled, any,race) Performance improve at least 240%, being tests executed faster now
Awesome job! Keep it up! 👊 |
For this solution I've adapted the exercises in order to have test for the solutions