Repository navigation
Conversation
crisbeto
force-pushed
the
test-component-bindings
branch
from
June 13, 2025 07:12
274b4a4 to
9611870
Compare
crisbeto
marked this pull request as ready for review
June 13, 2025 07:22
Adds support for passing in `Binding` objects into `TestBed.createComponent`. This makes it easier to test components by avoiding the need to create a wrapper component. Furthermore, it keeps the behavior consistent between tests and the actual app. For example, given a custom checkbox that looks like this: ```typescript @component({ selector: 'my-checkbox', template: '...', host: {'[class.checked]': 'isChecked()'} }) export class MyCheckbox { isChecked = input(false); } ``` A test for the `isChecked` input would look something like this: ```typescript it('should toggle the checked class', () => { @component({ imports: [MyCheckbox], template: '<my-checkbox [isChecked]="isChecked"/>', }) class Wrapper { isChecked = false; } const fixture = TestBed.createComponent(Wrapper); const checkbox = fixture.nativeElement.querySelector('my-checkbox'); fixture.detectChanges(); expect(checkbox.classList).not.toContain('checked'); fixture.componentInstance.isChecked = true; fixture.detectChanges(); expect(checkbox.classList).toContain('checked'); }); ``` Whereas with the new API, the test would look like this: ```typescript it('should toggle the checked class', () => { const isChecked = signal(false); const fixture = TestBed.createComponent(MyCheckbox, { bindings: [inputBinding('isChecked', isChecked)] }); const checkbox = fixture.nativeElement.querySelector('my-checkbox'); fixture.detectChanges(); expect(checkbox.classList).not.toContain('checked'); isChecked.set(true); fixture.detectChanges(); expect(checkbox.classList).toContain('checked'); }); ```
crisbeto
force-pushed
the
test-component-bindings
branch
from
June 14, 2025 05:00
9611870 to
49a1f83
Compare
thePunderWoman
approved these changes
Jun 16, 2025
thePunderWoman
left a comment
Contributor
There was a problem hiding this comment.
LGTM
reviewed-for: fw-general, public-api
atscott
approved these changes
Jun 16, 2025
atscott
left a comment
Contributor
There was a problem hiding this comment.
reviewed-for: public-api
Member
|
This PR was merged into the repository by commit 2e0c98b. The changes were merged into the following branches: main |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for passing in
Bindingobjects intoTestBed.createComponent. This makes it easier to test components by avoiding the need to create a wrapper component. Furthermore, it keeps the behavior consistent between tests and the actual app. For example, given a custom checkbox that looks like this:A test for the
isCheckedinput would look something like this:Whereas with the new API, the test would look like this: