Replacing $timeout with $interval for $mdToast for protractor
Since the $mdToast service uses $timeout to do the hiding delay, you are unable to e2e test toasts that have a hide delay.
An example test that fails:
toast.js
$mdToast.show(
$mdToast.simple()
.content('Saved')
.position('bottom right')
);
toast.spec.js
var saveAlert = element(by.css('md-toast'));
browser.wait(function(){
return browser.isElementPresent(saveAlert);
});
expect(saveAlert.getText()).toBe('Saved');
But, if you don't let it hide, the test will pass
$mdToast.show(
$mdToast.simple()
.content('Saved')
.position('bottom right')
.hideDelay(0)
);
Protractor handles $interval's better and does not wait for the interval to finish before processing. Protractor issue reference: https://github.com/angular/protractor/issues/169
:+1:
Just hit this issue while laying in protractor, I was thinking it was due to using cucumber.js and chaiAsPromissed, but just did the hide delay 0 and it is passing now, so will have to turn off this test till it is fixed...
+1 for fix
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1. Can you please change the priority of this issue. Writing code without automation backup is neither a good idea nor recommended.
+1
:+1:
+1
+1
When we're replacing $timeout with $interval, errors will appear in the Karma tests.
This is because, $interval is not able to not guarantee a given delay between executions.

There are several possibilities to fix that issue:
- Using async unit tests.
- Keeping
$timeoutand mention the use ofignoreSynchronization - Using
$intervaland provide a decorator inside the Material Mocks.
@ThomasBurleson
This issue is closed as part of our deprecation effort. For details, see our post Spring Cleaning 2016.