Skip to content

Commit

Permalink
fix(click): add an option to pass native element and debug element
Browse files Browse the repository at this point in the history
  • Loading branch information
Netanel Basal committed Apr 2, 2018
1 parent d94dbd9 commit fafe43d
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions src/lib/src/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,28 @@ export class Spectator<C> {

/**
*
* @param {string} selector
* @param selector string | Element | DebugElement
*/
click(selector: string) {
const element = this.debugElement.query(By.css(selector));
if (element) {
element.nativeElement.click();
this.detectChanges();
click(selector: string | Element | DebugElement) {
let element;

if (typeof selector === 'string') {
const checkExists = this.debugElement.query(By.css(selector));
if (checkExists) {
element = checkExists.nativeElement;
} else {
throw new Error(`${selector} does not exists`);
}
} else {
throw new Error(`${selector} does not exists`);
if (selector instanceof DebugElement) {
element = selector.nativeElement;
} else {
element = selector;
}
}

element.click();
this.detectChanges();
}

/**
Expand Down

0 comments on commit fafe43d

Please sign in to comment.