-
Notifications
You must be signed in to change notification settings - Fork 12k
fix(@angular/cli): Do not use floating promises, we can resolve these… #17652
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
fix(@angular/cli): Do not use floating promises, we can resolve these… #17652
Conversation
packages/schematics/angular/application/other-files/app.component.spec.ts.template
Outdated
Show resolved
Hide resolved
packages/schematics/angular/e2e/files/src/app.e2e-spec.ts.template
Outdated
Show resolved
Hide resolved
4573010
to
e948768
Compare
Please note that I've never really done an open source pull request before. If there is anything missing please let me know. |
e948768
to
b6f5bd4
Compare
beforeEach(async(() => { | ||
TestBed.configureTestingModule({<% if (routing) { %> | ||
beforeEach(async () => { | ||
return TestBed.configureTestingModule({<% if (routing) { %> |
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.
Is there any point in using async
if you are not await
ing the promise?
I would expect either async () => { await TestBed... }
or () => { return TestBed... }
.
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.
i'd probably go with await
to make it more explicit that it is an asynchronous operation and also slightly simplify future user additions (either before or after the call).
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.
I think async shouldn't only be used when awaiting, returning the promise also showcases asynchronous behavior.
@@ -1,11 +1,11 @@ | |||
import { browser, by, element } from 'protractor'; | |||
|
|||
export class AppPage { | |||
navigateTo(): Promise<unknown> { | |||
async navigateTo(): Promise<unknown> { |
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.
FWIW, you can also use PromiseLike<...>
here and not have to cast below.
Do you know if there are any downsides to using PromiseLike
?
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.
PromiseLike
is mainly useful when dealing with alternative implementations of promises (bluebird, etc.). The only real downside is that it won't be accepted for any consumer that expects a Promise
(e.g., function myFunc(p: Promise<unknown>) {}
).
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.
Also, no reason for async
here since you are not using await
.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
In this PR I've fixed some floating promises in the generation of component spec files and app.component.spec.ts.
Without this fix tslint errors occur when generating components when the tslint option 'no-floating-promises' is enabled.
Also see:
https://palantir.github.io/tslint/rules/no-floating-promises/