Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular.js e2e test and $timeout issue

I have a simple service for displaying flash messages https://github.com/lucassus/mongo_browser/blob/master/app/assets/javascripts/app/services.js.coffee#L31 and I'm trying to test it in e2e specs https://github.com/lucassus/mongo_browser/blob/master/spec/javascripts/e2e/databases_scenario.js.coffee#L66 I use $timeout service to hide a flash message after 3 seconds.

I noticed that e2e scenario runner blocks until the timeout flushes and I'm not able to check whether the flash message has been shown.

How to test features with $timeout in e2e specs? Is it possible to test this kind of behavior without injecting mock services into the real application?

like image 930
luacassus Avatar asked Jul 09 '26 03:07

luacassus


1 Answers

I don't see a way to call inject() in the end-to-end tests, as described by @christian-smith; this method is for the standard Jasmine tests, not the e2e test runner.

I've created a Plunker to demonstrate.

In the example, the call to $timeout(halfHourAction, 30*1000, false); in app.js means the tests don't start running for 30 seconds.

In my Real World® example, I'm actually polling something every 30minutes, so the app never starts running at all. Even being able to flush the $browsers queue would only add another method to it.

like image 154
Piran Avatar answered Jul 11 '26 17:07

Piran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!