No tienes acceso a esta clase

¬°Contin√ļa aprendiendo! √önete y comienza a potenciar tu carrera

Compra acceso a todo Platzi por 1 a√Īo

Antes: $249

Currency
$209/a√Īo

Paga en 4 cuotas sin intereses

Paga en 4 cuotas sin intereses
Suscríbete

Termina en:

13D
18H
44M
33S

Validadores async en Form

16/17
Recursos

Aportes 3

Preguntas 0

Ordenar por:

¬ŅQuieres ver m√°s aportes, preguntas y respuestas de la comunidad?

o inicia sesión.

Reto:

   it('Should show error with an email invalid', fakeAsync(() => {
      const inputDebug = query(fixture, 'input#email');
      const inputEl: HTMLInputElement = inputDebug.nativeElement;
      inputEl.value = "[email protected]"

      userService.isAvailableByEmail.and.returnValue(mockObservable({isAvailable: false}));
      tick();

      inputEl.dispatchEvent(new Event('input'));
      inputEl.dispatchEvent(new Event('blur'));
      fixture.detectChanges();
      const textError = getText(fixture, 'email-error-async');

      expect(component.emailField?.invalid).toBeTrue();
      expect(userService.isAvailableByEmail).toHaveBeenCalledWith("[email protected]");
      expect(textError).toContain('*The email is already registered')
    }))

Mi solución al reto:

it('should be show a message if the email is already registered', fakeAsync(() => {
  const emailNative: HTMLInputElement = emailDebug.nativeElement;
  const email = '[email protected]';
  userServiceSpy.isAvailableByEmail.and.returnValue(
    observableData({ isAvailable: false })
  );
  setValueOnInputElement(emailNative, email);

  fixture.detectChanges();
  tick();

  const errorNative: HTMLElement = query(
    fixture,
    'email-exists',
    true
  ).nativeElement;

  textContext = 'Method "isAvailableByEmail" should be called';
  expect(userServiceSpy.isAvailableByEmail).withContext(textContext).toHaveBeenCalledWith(email);
  textContext = 'Check if there is an error message';
  expect(errorNative).withContext(textContext).toBeDefined();
  expect(userServiceSpy.isAvailableByEmail).toHaveBeenCalledWith(email);
})); 

Reto

  it('should show error with an email invalid', () => {
    // Arrange
    userService.isAvailableByEmail.and.returnValue(
      mockObservable({ isAvailable: false })
    );
    setInputValue(fixture, 'input#email', '[email protected]');

    // Act
    fixture.detectChanges();
    // Assert
    expect(component.emailField?.invalid).withContext('true').toBeTrue();
    expect(userService.isAvailableByEmail)
      .withContext('isAvailableByEmail')
      .toHaveBeenCalledWith('[email protected]');
    const notAvalilableMsjEl = queryById(fixture, 'emailField-no-available');
    const errorMsj = getText(fixture, 'emailField-no-available');
    expect(notAvalilableMsjEl).withContext('to be exist').toBeTruthy();
    expect(errorMsj)
      .withContext('msj no available')
      .toEqual('The email is already registered');
  });