Reputation: 61
I'm trying to figure out how to properly write an Ember test helper that performs its own async operations and tests that themselves involve async operations not necessarily wrapped in async helpers. The examples on the Ember site here and here both show async test helpers that are merely constructed by calling pre-existing async helpers, not code that creates its own async condition.
Background: I'm working on a service that's going to have a REST back end fronted by Ember+Ember Data. I want to write some test code that talks to the actual server in order to allow us to work out details on how Ember-Data interacts with the server. (Before you jump up and down about how integration tests should use fake data so that they can be run in CI mode, what we've done is set up a separate Ember app whose sole purpose in life is to exercise the data model through Ember Data for the purposes of debugging the server. Thus, these are really server tests, designed to ensure the compatibility between the server and Ember Data, not integration tests on the Ember application itself.)
Thus, what some of the tests want to do is:
Both of the first two operates are clearly asynchronous. The first would very clearly be a nice async helper. The second doesn't necessarily have to be a helper because each invocation is going to be different, but clearly the test itself needs to wait on the promise that methods from DS.store
return.
Finally, other stuff I know:
click
, visit
) all finish with return app.testHelpers.wait();
wait
returns an instance of RSVP.Promise
which does a lot of processing to make sure things have more-or-less cleaned up before it resolves, including dealing with outstanding AJAX queries, test waiters, etc.wait
can interact with test waiters, if required.Thus, it would seem that if my async helper did the same thing as Ember's (i.e. return app.testHelpers.wait();
) this would be sufficient for my AJAX helper, since wait
would take care of waiting for the AJAX transaction to complete. This doesn't necessary answer the broader question, however.
OK, now the real questions:
If I want to write my own arbitrary async helper, is it sufficient for me to return an instance of RSVP.Promise
that will be resolved at the appropriate time? Or is it necessary to actually use the wait()
mechanism (and possibly test waiters) because of some additional Ember dependencies on the behavior of the wait
mechanism?
Does Ember have any special requirements for tests involving async operations mid-stream? Or are the QUnit mechanisms for async tests sufficient?
Does Ember have any kind of "wrapper" for the QUnit async stuff? (The way that it "hides" the QUnit-ness behind its set of test calls.)
Do Ember Data interactions with the server have a dependency on the Ember run loop?
OK, I think that's clearly enough for a single question. :) I greatly appreciate anybody who's willing to educate me.
Upvotes: 3
Views: 251
Reputation: 367
Trying to answer your questions with my experience with these issues which might be incomplete:
andThen
blocks will then wait for your promise to resolve before running as they do with built-in async helpers like visit.Ember.run
statementHope this helps
Upvotes: 0