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

Wrong context in asyncTest (using callbacks given to moduleFor instead of extended callbacks) #98

Closed
huafu opened this issue Oct 13, 2014 · 6 comments

Comments

@huafu
Copy link

huafu commented Oct 13, 2014

Using moduleFor is extending the 3rd argument (callbacks) to inject subject for example. This works for setup, teardown and any test, but any asyncTest has the un-modified callbacks given as 3rd argument to moduleFor instead of the one where subject has been injected.

In result, calling this.subject() in an asyncTest is failing since subject is then undefined

@stefanpenner
Copy link
Member

@huafu the idea is to use promises, and return promises in the main callback whenever one would need an async test. This typically provides a nicer asyncTest experience as it does all the start/stop balancing for you and also preserves context.

@huafu
Copy link
Author

huafu commented Oct 13, 2014

Sorry but do you have an example of how to do an async test with promises and this.subject even very simple, or link to where there might be one somewhere?

@rwjblue
Copy link
Member

rwjblue commented Oct 13, 2014

test('do something async', function() {
  return new Ember.RSVP.Promise(function(resolve, reject) {
    /* do something that does async */
    setTimeout(function() {
      /* when the async is done */
      resolve();
    }, 10);
  });
});

@rwjblue
Copy link
Member

rwjblue commented Oct 13, 2014

@rwjblue rwjblue closed this as completed Oct 13, 2014
@huafu
Copy link
Author

huafu commented Oct 14, 2014

Haha as simple as this! Thank you I wouldn't think it was that simple, forgot test where waiting for promise and other delayed stuff to finish, thanks a lot!

Huafu Gandon
Head of Tech, Sovolve, LLC
Skype: pedroleouf
www.sovolve.com
Social Evolution, Accelerated

Try Panomira.
You'll never look at yourself the same way again.

On 13 oct. 2014, at 19:53, Robert Jackson notifications@github.com wrote:

Closed #98.


Reply to this email directly or view it on GitHub.

@stefanpenner
Copy link
Member

Awesomely the latest Qunit will support this promise behavior right out of the box!

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