Skip to content

Instantly share code, notes, and snippets.

@sawyerbutton
Created October 26, 2021 09:25
Show Gist options
  • Select an option

  • Save sawyerbutton/5e7e5a73ae4a480c7625bbfa0f1d7f28 to your computer and use it in GitHub Desktop.

Select an option

Save sawyerbutton/5e7e5a73ae4a480c7625bbfa0f1d7f28 to your computer and use it in GitHub Desktop.

Input Unit test

it('should correctly render the passed @Input value', () => {
  component.message = 'Enter a new title'; // input value modify
  fixture.detectChanges(); // make change
  const compiled = fixture.debugElement.nativeElement; // compiled component
  expect(compiled.querySelector('p').textContent).toBe('Enter a new title'); // component content verify
});

Output Unit test

it('should correctly @Output value of text input in component', () => {
  spyOn(component.changeTitleEvent, 'emit'); // emit spy
  const button = fixture.nativeElement.querySelector('button');
  fixture.nativeElement.querySelector('input').value = 'A new title'; // 2
  const inputText = fixture.nativeElement.querySelector('input').value;
  
  button.click(); // 3
  fixture.detectChanges();
 
  expect(component.changeTitleEvent.emit).toHaveBeenCalledWith(inputText); // 4
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment