Created
May 27, 2023 12:58
-
-
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
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
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