WorldMaker/angular-pharkas

Refactor around ChangeDetectorRef for increased testability?

WorldMaker opened this issue · 1 comments

Right now the clearest thing standing in the way of building some "marble diagrams" tests for Pharkas is that Angular ChangeDetectorRef dependency which is entirely imperative.

Some sort of ChangeDetectorObserver (ChangeDetectionSubject?) wrapper intermediary could speak Observable<T> more naturally and avoid the internal subscribes in testing cases and allow us to simply use "marble diagrams" testing. My biggest concern about the external API change is if we move to base constructor(ref: ChangeDetectorRef | ChangeDetectorObserver) and there aren't more general uses of ChangeDetectorObserver if it might confuse people on how to inject derived classes. (Everyone seems to think Angular is "testable" because it includes useless and broken tests out of the box yet here contemplating real testing and we are left with a hard dependency on a nigh untestable imperative backdoor keeping us from doing cleaner RxJS testing.)

Bookmarking here for later if I do sort out this refactoring pain, nice mocha and chai wrappers: https://github.com/rxjs-stuff/marbles

That rxjs-stuff repo is out of date. Just using the built-in at this point should be easy enough: https://rxjs.dev/guide/testing/marble-testing

Unfortunately what I really want for virtual timing is the animate() helper which doesn't exist until v8 and Angular 13 is still on v6.

I found out that I can't get mocha working directly because of @angular/core inputs are not ESM safe in Angular 13. I was able to get Jest tests running (thanks to schematic @briebug/jest-schematic but the tests are useful without animate().