Skip to content

Instantly share code, notes, and snippets.

@AlejoDev95
Created May 27, 2023 12:58
Show Gist options
  • Save AlejoDev95/4ead4c4092333eb9e0a538ad2bb6f0bb to your computer and use it in GitHub Desktop.
Save AlejoDev95/4ead4c4092333eb9e0a538ad2bb6f0bb to your computer and use it in GitHub Desktop.
Conjunto de funciones que nos van a pemitir simular un click en nuestras pruebas unitarias
import { ComponentFixture } from '@angular/core/testing';
import { queryByTestId, query } from './finder';
export function clickEvent<T>(
fixture: ComponentFixture<T>,
selector: string,
withTestId = false,
eventName = 'click',
event: unknown = null
) {
const element = withTestId
? queryByTestId(fixture, selector)
: query(fixture, selector);
element.triggerEventHandler(eventName, event);
}
export function clickElement<T>(
fixture: ComponentFixture<T>,
selector: string,
withTestId = false
) {
const elementDebug = withTestId
? queryByTestId(fixture, selector)
: query(fixture, selector);
const element: HTMLElement = elementDebug.nativeElement;
element.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment