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

fix(cdk/testing): strongly type return value of TestElement.getProperty #22918

Merged
merged 1 commit into from
Jul 2, 2021

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Jun 8, 2021

Allows for the return value of TestElement.getProperty to be typed strongly through a generic parameter.

@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jun 8, 2021
@crisbeto crisbeto requested a review from mmalerba June 8, 2021 06:00
@crisbeto crisbeto requested review from devversion, jelbourn and a team as code owners June 8, 2021 06:00
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 8, 2021
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -206,8 +206,8 @@ export class ProtractorElement implements TestElement {
}

/** Gets the value of a property of an element. */
async getProperty(name: string): Promise<any> {
return browser.executeScript(`return arguments[0][arguments[1]]`, this.element, name);
async getProperty<T = any>(name: string): Promise<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

ideally we'd make the default unknown but I guess maybe that's too breaking?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I suspect that unknown will be breaking. I doubt that getProperty is used too often since most of the time you can get the same information through getAttribute.

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jun 9, 2021
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM, but we should see if we can change this to unknown for v13

Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

LGTM. Agreed on unknown being better in the future; we could have a migration for that.

async getProperty(name: string): Promise<any> {
return browser.executeScript(`return arguments[0][arguments[1]]`, this.element, name);
async getProperty<T = any>(name: string): Promise<T> {
return browser.executeScript<T>(`return arguments[0][arguments[1]]`, this.element, name);
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that google's internal typings do not support a generic version of executeScript can you change this to return browser.executeScript(...) as any

@mmalerba mmalerba removed the action: merge The PR is ready for merge by the caretaker label Jun 17, 2021
Allows for the return value of `TestElement.getProperty` to be typed strongly through a generic parameter.
@crisbeto
Copy link
Member Author

Done. Also rebased.

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jun 17, 2021
@andrewseguin andrewseguin merged commit b682f84 into angular:master Jul 2, 2021
andrewseguin pushed a commit that referenced this pull request Jul 2, 2021
…ty (#22918)

Allows for the return value of `TestElement.getProperty` to be typed strongly through a generic parameter.

(cherry picked from commit b682f84)
@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 Aug 2, 2021
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 cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants