Skip to content

Instantly share code, notes, and snippets.

@Serrulien
Serrulien / custom-jasmine-matcher.ts
Last active November 11, 2019 15:01
Jasmine custom matcher for Angular's DebugElement
// Better use this matcher than using toBeNull or toBeUndefined to test a DebugElement so as to avoid freezing the test.
// When expecting a DebugElement to be null but is not, jasmine will create a gigantic string describing the DebugElement.
// More on https://medium.com/@martatatiana/poor-detective-angular2-browser-crash-and-debugelement-f0a651dbf33
// e.g. expect(fixture.debugElement.query(By.css("img:first-of-type"))).toDebugElemExists();
// you can also use .not to negate the matcher.
beforeEach(() => {
jasmine.addMatchers({
toDebugElemExists: function (utils, customEqualityTesters) {
return {