Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(core): rename async to waitForAsync to avoid confusing #37583

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

Closed
wants to merge 2 commits into from

Conversation

JiaLiPassion
Copy link
Contributor

@JiaLiPassion JiaLiPassion commented Jun 15, 2020

@angular/core/testing provide async test utility, but the name async is
confusing with the javascript keyword async. And in some test case, if you
want to use both the async from @angular/core/testing and async/await,
you may have to write the code like this.

function asyncFunc(): Promise<{value: number}> {
    return new Promise(res => setTimeout(() => { res({value: 1}); }));
  }

  function timeout(obj) {
    setTimeout(() => {
      obj.value += 1;
    });
  }

  it('test async', async () => {
    const r: {value: number} = await asyncFunc();
    timeout(r);
    setTimeout(() => {
      expect(r.value).toBe(2);
    });
   });

So in this PR, the async is renamed to asyncTest.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@JiaLiPassion JiaLiPassion added area: testing Issues related to Angular testing features, such as TestBed breaking changes area: core Issues related to the framework runtime target: major This PR is targeted for the next major release labels Jun 15, 2020
@JiaLiPassion JiaLiPassion requested a review from mhevery June 15, 2020 05:00
@ngbot ngbot bot added this to the needsTriage milestone Jun 15, 2020
@ngbot ngbot bot modified the milestone: needsTriage Jun 15, 2020
@petebacondarwin petebacondarwin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 15, 2020
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Reviewed-for: fw-upgrade

Don't forget to update: https://github.com/angular/angular/blob/efdf347f9c04e19c8c4fa8b8c05f4310f42728d5/aio/content/guide/upgrade-setup.md

Otherwise LGTM

And I believe you are also going to rename fakeAsync() too.

@clydin
Copy link
Member

clydin commented Jun 15, 2020

Can you provide some details on when a developer would need to use this:

it('test async operations', async(async() => {
  const result = await asyncMethod();
  expect(result).toEqual('expected');
}));

instead of this:

it('test async operations', async () => {
  const result = await asyncMethod();
  expect(result).toEqual('expected');
});

@jelbourn
Copy link
Member

@JiaLiPassion I'm personally missing some context on this; is this something that's been previously proposed/discussed with the larger team?

@JiaLiPassion
Copy link
Contributor Author

JiaLiPassion commented Jun 17, 2020

@jelbourn, there is no discussion about this one, I just want to make a proposal by making this PR so it may easier to review and discuss. And yeah, I think we need to discuss this one first otherwise it may cause confusion to the community. I will close this PR for now, thank you.

@JiaLiPassion JiaLiPassion reopened this Jun 29, 2020
@JiaLiPassion JiaLiPassion force-pushed the change-async-name branch 4 times, most recently from 1040b87 to bee367a Compare June 30, 2020 09:26
@mary-poppins
Copy link

You can preview f494e53 at https://pr37583-f494e53.ngbuilds.io/.

@shairez
Copy link
Contributor

shairez commented Jul 26, 2020

Thanks for the consideration everyone! good job @JiaLiPassion ! 💗

@JiaLiPassion
Copy link
Contributor Author

@petebacondarwin , yeah, I updated the format and commit again, please review, thanks.

Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

Reviewed-for: fw-upgrade

@pullapprove pullapprove bot requested a review from atscott July 28, 2020 17:03
@mary-poppins
Copy link

You can preview 4a63d18 at https://pr37583-4a63d18.ngbuilds.io/.

@mary-poppins
Copy link

You can preview a0d0dce at https://pr37583-a0d0dce.ngbuilds.io/.

@mhevery
Copy link
Contributor

mhevery commented Jul 30, 2020

presubmit

Copy link
Contributor

@mhevery mhevery left a comment

Choose a reason for hiding this comment

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

LGTM

  • Sorry to be a pain, but could you break the PR into two. One for the change, and one to move async to waitForAsync We had it broken up but somehow it gote merged.

Reviewed-for: global-approvers
Reviewed-for: fw-core

@mhevery mhevery added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jul 30, 2020
@angular/core/testing provide `async` test utility, but the name `async` is
confusing with the javascript keyword `async`. And in some test case, if you
want to use both the `async` from `@angular/core/testing` and `async/await`,
you may have to write the code like this.

```typescript
it('test async operations', async(async() => {
  const result = await asyncMethod();
  expect(result).toEqual('expected');
}));
```

So in this PR, the `async` is renamed to `waitForAsync` and also deprecate `async`.
The last commit change `async` to `waitForAsync`.
This commit update all usages in the code and also update aio doc.
@mary-poppins
Copy link

You can preview e20abd9 at https://pr37583-e20abd9.ngbuilds.io/.

@JiaLiPassion JiaLiPassion removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Jul 31, 2020
@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Jul 31, 2020
@mhevery
Copy link
Contributor

mhevery commented Jul 31, 2020

presubmit deflake

@mhevery mhevery added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Aug 3, 2020
@mhevery
Copy link
Contributor

mhevery commented Aug 3, 2020

merge-assistance: global-approval

@alxhub alxhub closed this in 8f07429 Aug 3, 2020
alxhub pushed a commit that referenced this pull request Aug 3, 2020
#37583)

The last commit change `async` to `waitForAsync`.
This commit update all usages in the code and also update aio doc.

PR Close #37583
@JiaLiPassion JiaLiPassion changed the title feat(core): rename async to asyncTest to avoid confusing feat(core): rename async to waitForAsync to avoid confusing Aug 6, 2020
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…37583)

@angular/core/testing provide `async` test utility, but the name `async` is
confusing with the javascript keyword `async`. And in some test case, if you
want to use both the `async` from `@angular/core/testing` and `async/await`,
you may have to write the code like this.

```typescript
it('test async operations', async(async() => {
  const result = await asyncMethod();
  expect(result).toEqual('expected');
}));
```

So in this PR, the `async` is renamed to `waitForAsync` and also deprecate `async`.

PR Close angular#37583
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
angular#37583)

The last commit change `async` to `waitForAsync`.
This commit update all usages in the code and also update aio doc.

PR Close angular#37583
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime area: testing Issues related to Angular testing features, such as TestBed breaking changes cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.