Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue testing page with moment-from-now #80

Closed
Iftahh opened this issue Aug 12, 2015 · 9 comments
Closed

issue testing page with moment-from-now #80

Iftahh opened this issue Aug 12, 2015 · 9 comments

Comments

@Iftahh
Copy link

Iftahh commented Aug 12, 2015

My acceptance tests stopped working in pages where I added the moment-from-now with an interval.

The tests start with visit to a url, followed by andThen containing the asserts.
Unfortunately the tests fail with a timeout and the andThen isn't called.

I'm guessing the problem is the endless Ember.runLater that the testing framework waiting for all the jobs queue to empty before activating the next andThen.

Without passing an interval to the moment-from-now the tests work as expected.

This issue isn't specific to ember-moment. It was reported to Ember since 2013 and still is open - see emberjs/ember.js#3008
@teddyzeenny provided a workaround in that thread, ie. instead of runLater use:
setTimeout(function() { Em.run(function() { //.. code here } });

@jasonmit
Copy link
Collaborator

Ember.run.cancel to cancel anything outstanding on the run loop queue. It's something you want to get into the habit with testing.

@Iftahh
Copy link
Author

Iftahh commented Aug 13, 2015

@jasonmit Perhaps I misunderstood you, or you misunderstood me...
the testing code looks like this:

test: function() {
   visit("/pending-users");
   andThen(function() {
      assert(...page contains what is expected...);
   }
}

Where would I place the cancel? The only place that makes sense is between the visit to the andThen.
What timer should I pass to the cancel? it accepts a parameter, but there is no way to know the runlater timer set by ember-moment.
Attempting to use instead the (private) method Ember.run.cancelTimers() failed even more tests... I did not debug exactly why.

@jasonmit
Copy link
Collaborator

@Iftahh sorry, I do think I misunderstood. Is your project public so I can step through this?

@stefanpenner have anything better in mind than replacing the Ember.run.later with setTimeout + Ember.run?

https://github.com/stefanpenner/ember-moment/blob/master/addon/helpers/moment-from-now.js#L12

@stefanpenner
Copy link
Collaborator

@jasonmit seems like the timer should be canceled in destroy() of that helper

@jasonmit
Copy link
Collaborator

👍 will fix shortly

@stefanpenner
Copy link
Collaborator

that wont help the above issue, as the timerwaiters in the test helpers are not granular enough.

The solution in ember will land shortly have async/await is supported in jshint, which will revamp the test helpers. Long story, upside @teddyzeenny and myself spike it was ember conf, it was wonderful and glorious but was blocked on tooling (just jshint) support, and stage 2 TC39 support.

In the interim: you should work-around this, by doing both: #80 (comment)

and the suggested raw setTimeout + Ember.run trick, which wont insert a test waiter, like run.later will.

@Iftahh
Copy link
Author

Iftahh commented Aug 13, 2015

Thank you @jasonmit and @stefanpenner for your quick responses and fix !

@jasonmit my code isn't open source but you should be able to reproduce it very easily -
use ember cli to generate acceptance-test and visit a page containing moment-from-now helper somewhere in the template - that should be enough.

@jasonmit
Copy link
Collaborator

3.5.1 published, take it for a spin and report if this issue persists.

P.S., I only fixed this because of your avatar photo.

@stefanpenner
Copy link
Collaborator

Thanks @jasonmit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants