Creating an asynchronous component test with mocha/chai


#1

I’m trying to figure out the proper way to make a component integration test that involves asynchronous behavior. I seem to bounce back and forth between “calling set on a destroyed object” and “wrap asynchronous behavior in a run”. Here’s a Twiddle of it working in QUnit, but in Mocha the assertions are run before the promise resolves.

Any pointers? Thanks!


#2

Got some help and it’s all working now. There are a few different parts:

  • use wait() in your tests between execution and assertions, to wait for promises to resolve (import from ember-test-helpers/wait).
  • either use wait().then(... or async/await to block until the wait completes.
  • wrap any this.set('... in your component with Ember.run(

#3

Hi,

Just from my own work trying to get tests to work in Ember with Mocha I would recommend not bothering as I don’t think it’s stable. I wasted a lot of time trying to do it on a few projects without success.

I would recommend just sticking with the built in Qunit as it has better support. If you need a more robust way try out CapserJS instead or better yet Selenium.

I know this may not be helpful but I spent a lot of time trying to get this working well and failed,

Pete


#4

I’m able to test everything in my async components now with mocha. If there’s something specific you weren’t able to get working I’d be happy to look at it.