launchdarkly / js-client-sdk

LaunchDarkly Client-side SDK for Browser JavaScript
Other
112 stars 65 forks source link

Support Angular4 Testability #49

Closed ahofman closed 4 years ago

ahofman commented 7 years ago

When integrating ldclient-js with an Angular4 application, the Angular4 Testability service is not usable as the testability never becomes stable after an ldclient is initialized.

For example, window.getAllAngularTestabilities()[0].isStable() is always false.

The testability is considered "stable" when there are no "macro tasks" still pending. According to this, The setTimeout calls used by the ld client are macro tasks, and because the ld client uses an infinite loop of setTimeout calls there is always a macro task pending, and therefore the testability is never stable.

A similar issue exists when using angular-google-maps with the testability service: https://github.com/SebastianM/angular-google-maps/issues/815

I'm no JS expert so I'm not sure how this could be solved - do we need a separate client library that specifically targets Angular4?

MartinNuc commented 6 years ago

I am wondering - would mocking your LD service help?

jemerald commented 5 years ago

Unfortunately, no.

Angular Testability is for e2e tests (using frameworks such as protractor), so mocking the LD service is not really an option.

jemerald commented 5 years ago

My current workaround is to add backdoor hooks in my LD service that check special flags in localStorage and not initialise launch-darkly client.

So before all the tests I'll need to:

  1. open application
  2. set flag in localStorage
  3. refresh browser (so that the hook is applied)

It would be awesome if the library can be enhanced to play nice with Angular Testability

mpienkowski commented 5 years ago

It works fine if you initialize Launch Darkly outside of Angular (in callback of NgZone#runOutsideAngular())

bwoskow-ld commented 4 years ago

Hi all,

We don't currently have any Angular-specific support in our JavaScript SDK and we don't have any plans to change this. Consequently I'm going to close this issue now; I'm hopeful that @mpienkowski's solution works for others.

Cheers, Ben Engineering Manager, LaunchDarkly