Last active
December 19, 2018 08:22
-
-
Save rctay/9fa77f9ba9bc763307a74f7aadf8de7b to your computer and use it in GitHub Desktop.
Testing handlers and their bindings
This file contains 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
<form [formGroup]="teamFormGroup" id="team-details__form"> | |
<input matInput placeholder="Team Name" name="teamName" formControlName="teamName"> | |
<button type="submit" mat-raised-button | |
(click)="onSaveChangesClicked()" | |
id="details__save-changes" | |
color="primary">save changes | |
</button> | |
</form> |
This file contains 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
describe('MyComponent', () => { | |
describe('Save Changes button', () => { | |
it('should be present', () => { | |
expect(fh.findByCss('#details__save-changes')).toBeTruthy(); | |
}); | |
describe('(click)', () => { | |
it('should delegate to onSaveChangesClicked()', () => { | |
const spy = jasmine.createSpy('Save Changes click handler'); | |
component.onSaveChangesClicked = () => spy(); | |
fh.findByCss('#details__save-changes').nativeElement.click(); | |
expect(spy).toHaveBeenCalled(); | |
}); | |
}); | |
}); | |
describe('onSaveChangesClicked()', () => { | |
it('should call service', () => { | |
component.teamFormGroup.get('teamName').setValue('an updated name'); | |
component.onSaveChangesClicked(); | |
expect(teamDetailsServiceSpies.update).toHaveBeenCalledWith({ | |
name: 'an updated name', | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment