material icon indicating copy to clipboard operation
material copied to clipboard

Replacing $timeout with $interval for $mdToast for protractor

Open adamweeks opened this issue 11 years ago • 18 comments

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

adamweeks avatar May 04 '15 18:05 adamweeks

:+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...

andrew-cunliffe avatar Jul 02 '15 17:07 andrew-cunliffe

+1 for fix

itrethan avatar Sep 29 '15 06:09 itrethan

+1

sricc avatar Sep 29 '15 18:09 sricc

+1

fedelopez avatar Oct 12 '15 23:10 fedelopez

+1

pieterwillaert avatar Oct 20 '15 08:10 pieterwillaert

+1

AdamMcCormick avatar Oct 28 '15 19:10 AdamMcCormick

+1

dacarley avatar Oct 30 '15 21:10 dacarley

+1

TylerDixon avatar Nov 02 '15 19:11 TylerDixon

+1

jasonmc86 avatar Nov 03 '15 08:11 jasonmc86

+1

stefan-- avatar Nov 10 '15 07:11 stefan--

+1

bclin2 avatar Dec 04 '15 00:12 bclin2

+1. Can you please change the priority of this issue. Writing code without automation backup is neither a good idea nor recommended.

zaknuces avatar Dec 17 '15 16:12 zaknuces

+1

mprokopowicz avatar Feb 28 '16 14:02 mprokopowicz

:+1:

BelfordZ avatar Mar 10 '16 01:03 BelfordZ

+1

edgarchinchilla avatar Apr 01 '16 15:04 edgarchinchilla

+1

podoler avatar Apr 03 '16 22:04 podoler

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.

image

There are several possibilities to fix that issue:

  • Using async unit tests.
  • Keeping $timeout and mention the use of ignoreSynchronization
  • Using $interval and provide a decorator inside the Material Mocks.

@ThomasBurleson

devversion avatar Apr 13 '16 16:04 devversion

This issue is closed as part of our deprecation effort. For details, see our post Spring Cleaning 2016.

ThomasBurleson avatar Apr 28 '16 20:04 ThomasBurleson