Skip to content

Instantly share code, notes, and snippets.

@AlejoDev95
Created May 27, 2023 13:00
Show Gist options
  • Save AlejoDev95/1952bdc2a1ed35cef67aaad8c04d3f53 to your computer and use it in GitHub Desktop.
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
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