# Creating an asynchronous component test with mocha/chai

**URL:** <https://discuss.emberjs.com/t/creating-an-asynchronous-component-test-with-mocha-chai/12260>\
**Category:** Testing\
**Created:** [January 15, 2017, 10:26pm UTC](https://discuss.emberjs.com/t/creating-an-asynchronous-component-test-with-mocha-chai/12260 "2017-01-15T22:26:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dfalling](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@dfalling](https://discuss.emberjs.com/u/dfalling)\
**Post date:** [January 15, 2017, 10:26pm UTC](https://discuss.emberjs.com/t/creating-an-asynchronous-component-test-with-mocha-chai/12260/1 "2017-01-15T22:26:59Z")

</div>

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](https://canary.ember-twiddle.com/e5a28fecb02c48a7ab71472d8c9ea298?openFiles=tests.integration.components.search-component-test.js%2Ctemplates.components.search-component.hbs) of it working in QUnit, but in Mocha the assertions are run before the promise resolves.

Any pointers? Thanks!

---

<div class="post-metadata">

**Author:** ![dfalling](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@dfalling](https://discuss.emberjs.com/u/dfalling)\
**Post date:** [January 18, 2017, 5:36am UTC](https://discuss.emberjs.com/t/creating-an-asynchronous-component-test-with-mocha-chai/12260/2 "2017-01-18T05:36:29Z")

</div>

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(`

---

<div class="post-metadata">

**Author:** ![peter\_watters](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/peter_watters/32/12893_2.png) [@peter\_watters](https://discuss.emberjs.com/u/peter_watters)\
**Post date:** [January 18, 2017, 3:12pm UTC](https://discuss.emberjs.com/t/creating-an-asynchronous-component-test-with-mocha-chai/12260/3 "2017-01-18T15:12:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dfalling](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@dfalling](https://discuss.emberjs.com/u/dfalling)\
**Post date:** [January 18, 2017, 9:41pm UTC](https://discuss.emberjs.com/t/creating-an-asynchronous-component-test-with-mocha-chai/12260/4 "2017-01-18T21:41:31Z")

</div>

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.
