Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it recommended to set Ember.testing = true for unit tests?

Tags:

ember.js

We've recently started to use the undocumented Ember.testing flag in our jasmine specs which effectively disables the autorun runloop feature. We've found that this requires us to be quite a bit more explicit about manually wrapping code in runloops but has also given us more stability in our specs as it highlights problems in the way we've written the spec and helps to document when bindings are important to the code under test.

Is there an official line on the usage of this feature ? It appears to have had quite a positive impact in our app but I suspect most people aren't aware of it.

like image 852
Rob Monie Avatar asked Jan 09 '12 08:01

Rob Monie


1 Answers

Yes, you should definitely set Ember.testing = true in your tests.

Without Ember.testing, runloops are scheduled automatically with setTimeout, which is where the instability you're noting comes from.

Note: At the moment, when you activate Ember.testing, you necessarily end up prefixing many of the lines in your test code with Em.run =>, like

Em.run => obj.set('someProperty', true)

If you forget to, it will complain loudly, or properties/app state won't have updated when you try to run assertions against it.

Maybe this will be improved some day, but for now it's nothing to be worried about if your test code is sprinkled with run calls.

like image 156
Jo Liss Avatar answered Oct 17 '22 19:10

Jo Liss