0

I have a component with a @Attribute decorator as parameter. I did a test on it but sonar tells me that my builder’s line is not 100% covered on the branch. It highlights me 'green' in yellow. I would have liked to know how to cover it

export class CompStatusColorComponent{

  constructor(@Attribute('colorStatut') public colorStatut: string = 'green') { 
    this.colorStatut = colorStatut || 'green';
  }
  ngOnInit(): void {
  }

}

1 Answer 1

1

When the parameter colorStatut is undefined, it will be initialized with the default value 'green'. Therefore, beside providing a specific value, you'll probably also have to provide null for parameter colorStatut in order to obtain full test coverage.

For further details see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.