Angular2: `ChangeDetectorRef` is not injectable on Tests

ChangeDetectorRef cannot be injected on test bed! You’ll need to directly spy on them.

it('should call markForCheck when do a barrel roll.', () => {
	const changeDetectorRef = fixture.debugElement.injector.get(ChangeDetectorRef);
	const detectChangesSpy = spyOn(changeDetectorRef.constructor.prototype, 'markForCheck');

	doABarrelRoll();

	expect(detectChangesSpy).toHaveBeenCalled();
});

References:

Disclaimer:

Not all articles here are meant to be correct. My notes might be wrong or may no longer be relevant. If you want to try things here, please proceed with caution.


Posted

in

by

Tags: