Skip to content

Instantly share code, notes, and snippets.

@rctay
Last active December 19, 2018 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rctay/9fa77f9ba9bc763307a74f7aadf8de7b to your computer and use it in GitHub Desktop.
Save rctay/9fa77f9ba9bc763307a74f7aadf8de7b to your computer and use it in GitHub Desktop.
Testing handlers and their bindings
<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>
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