Skip to content

fix(tooltip): exception if mdTooltip is not a string #6146

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 1 commit into from
Closed

fix(tooltip): exception if mdTooltip is not a string #6146

wants to merge 1 commit into from

Conversation

rafaelss95
Copy link
Contributor

@rafaelss95 rafaelss95 commented Jul 29, 2017

Fixes an error that is thrown if something rather than a string is passed via [mdTooltip] @Input, i.e:

@Component({
  selector: 'some-selector',
  template: '<div [mdTooltip]="myNumber">Content</div>'
})
export class SomeClass {
  
  myNumber = 3;
}

Results in the following error:

this._message.trim is not a function

PLUNKER

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 29, 2017
@crisbeto
Copy link
Member

crisbeto commented Jul 30, 2017

Can you add a unit test for this? It should look something along the lines of this:

it('should not throw when a truthy non-string is passed in', () => {
  tooltipDirective.message = {};

  expect(() => {
    fixture.detectChanges();
    tooltipDirective.show();    
  }).not.toThrow();
});

@rafaelss95
Copy link
Contributor Author

@crisbeto I can't do this. It gives me error (the method signature asks for a string):

Type '{}' is not assignable to type 'string'.

@crisbeto
Copy link
Member

crisbeto commented Jul 31, 2017

Since it's only a test component, you can change the property signature to any.

@rafaelss95
Copy link
Contributor Author

I'm not sure I follow what you mean. tooltipDirective is an instance of MdTooltip and there the signature of set message(..) accepts (only) a string:

 set message(value: string) {
   this._message = value;
   this._setTooltipMessage(this._message);
 }

@crisbeto
Copy link
Member

I was talking about one of the test components here: https://github.com/angular/material2/blob/master/src/lib/tooltip/tooltip.spec.ts#L523

@rafaelss95
Copy link
Contributor Author

rafaelss95 commented Jul 31, 2017

Changing message from string to any (in BasicTooltipDemo component) still fail.

@rafaelss95
Copy link
Contributor Author

rafaelss95 commented Sep 13, 2017

Closing due to #7018 and #7024. Btw, the PRs doesn't have any tests as well...

@rafaelss95 rafaelss95 closed this Sep 13, 2017
@rafaelss95 rafaelss95 deleted the fix-tooltip branch September 20, 2017 00:10
@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants