Created
May 27, 2023 13:00
-
-
Save AlejoDev95/1952bdc2a1ed35cef67aaad8c04d3f53 to your computer and use it in GitHub Desktop.
Conjunto de funciones que nos permiten asignar un valor a los elementos de un input
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 { queryById, query } from './finder'; | |
import { ComponentFixture } from '@angular/core/testing'; | |
export function setInputValue<T>( | |
fixture: ComponentFixture<T>, | |
selector: string, | |
value: string, | |
withTestById = false | |
) { | |
const inputDe = withTestById ? queryById(fixture, selector) : query(fixture, selector); | |
const inputEl: HTMLInputElement = inputDe.nativeElement; | |
inputEl.value = value; | |
inputEl.dispatchEvent(new Event('input')); | |
inputEl.dispatchEvent(new Event('blur')); | |
} | |
export function setCheckboxValue<T>( | |
fixture: ComponentFixture<T>, | |
selector: string, | |
value: boolean, | |
withTestById = false | |
) { | |
const inputDe = withTestById ? queryById(fixture, selector) : query(fixture, selector); | |
const inputEl: HTMLInputElement = inputDe.nativeElement; | |
inputEl.checked = value; | |
inputEl.dispatchEvent(new Event('change')); | |
inputEl.dispatchEvent(new Event('blur')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment