Skip to content

Instantly share code, notes, and snippets.

@ManuelDeLeon
Created April 13, 2020 02:55
Show Gist options
  • Save ManuelDeLeon/a27ac1af2a0f7bb6a2609c414c51a240 to your computer and use it in GitHub Desktop.
Save ManuelDeLeon/a27ac1af2a0f7bb6a2609c414c51a240 to your computer and use it in GitHub Desktop.
it("Clicking the clear button calls clear on the message service", () => {
const messagesService = TestBed.get(MessageService);
messagesService.messages = [{}];
spyOn(messagesService, "clear");
fixture.detectChanges();
const button: HTMLButtonElement = fixture.debugElement.query(
By.css("button")
).nativeElement;
button.click();
// No need to detect changes because we're not checking changes in the DOM
expect(messagesService.clear).toHaveBeenCalled();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment