What is the best thing to do to avoid name collision between development/production environment and testing environment for ember based application.
Usually, every Ember application has a namespace :
window.MyApp = Em.Application.create();
in production, I run some initialization functions by redefining the ready property of Em.Application
window.MyApp = Em.Application.create(
ready: function() {
// create some objects
}
);
But, in my test enviroment, I don’t want to run these initialization functions because I create objects myself. Using the same definition of MyApp causes a collision because objects I create insert the same element in the DOM. So how can I use the same namespace MyApp without the ready function when I test my application ? I use jasmine to test the application.
I keep the glue code which instantiates my controllers, creates and setups views out of the
Application#readyfunction.Take pangratz/ember.js-dashboard for an example:
core.jsholds just theNamespacedefinitiion, whereascontrollers.js,views.jsand so on define my classes. The glue code which instantiates the controllers, creates the views and setups the bindings is defined inmain.js. Themain.jsis then used among the others in the ‘real’ application in theindex.html.I use interline/ember-skeleton for the basic application layout, which itself uses QUnit for testing. But this should be applicable for Jasmine too.