docs: update attribute testing guide to include canonical example wit…#69878
docs: update attribute testing guide to include canonical example wit…#69878mfstapert-xip wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
| it("should update the directive's input", async () => { | ||
| fixture.componentRef.setInput('color', 'blue'); | ||
| await fixture.whenStable(); | ||
|
|
||
| const debugElement = fixture.debugElement.query(By.directive(Highlight)); | ||
| const highLight = debugElement.injector.get(Highlight); | ||
| expect(highLight.bgColor()).toBe('blue'); | ||
| }); |
There was a problem hiding this comment.
i would drop that test which is a bad example. It's basically testing the implementation rather than the feature it provides.
There was a problem hiding this comment.
Agreed, this also makes the last sentence redundant
|
|
||
| it('should fall back to the default color when no color is provided', () => { | ||
| const p = fixture.nativeElement.querySelector('p'); | ||
| expect(p.style.backgroundColor).toBe('rgb(211, 211, 211)'); // default light gray color |
There was a problem hiding this comment.
That test would fail, as we don't have a default color. We could set the input default value to it.
There was a problem hiding this comment.
Ran this locally and it should pass with the directive at the top of this page. But this might be confusing to readers who only look for this section so I dropped this case.
…h local component
cf9c2e2 to
407fc61
Compare
PR Checklist
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Current guide on testing directives does not provide a explicit example of unit testing directives with new input signals syntax.
What is the new behavior?
This doc contains an example on how to unit test a directive using a local component to drive the directive.
Does this PR introduce a breaking change?
No
Other information
Reason for adding this is this thread: #54164
Hopefully this closes this issue.