Re: [ServiceWorker] Promise on navigator.serviceWorker that resolves when page is controlled (#799)

The "gotcha"/failure came up in the context of writing a unit test, where the code to execute *really* had to wait until the page was controlled, or it wouldn't end up testing the right thing. I had originally written the test to wait on `.ready`, and then got confused when the test ended up being flaky.

I now understand why the test was flaky, and am using a [synthetic `.controlled` promise](https://github.com/PolymerElements/platinum-sw/blob/master/test/controlled-promise.js) instead.

So that's the main use case I have in mind, and I think that it's a common enough pattern for anyone writing tests. Whether we ask everyone writing tests that depend on the page being controlled to roll their own `controllerchange` listener, or whether it gets added natively to the spec is obviously a matter for debate.

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/799#issuecomment-165501396

Received on Thursday, 17 December 2015 16:29:41 UTC