jnicklas/evergreen — Issue #47: Is require async?
Author: bradrobertson
Created: 2012-01-18 14:56:29+00:00
State: open

I'm a but stumped getting some helpers to work in my spec_helper.

I have `spec_helper` a file like so:

require("/javascripts/my_app.js");

console.log("myNamespace", myNamespace);

`my_app.js` defines the `myNamespace`

In my test however, I get an error:

> Uncaught reference error myNamespace is not defined

So this leads me to believe that require is asynchronous. BUT, then I don't understand how any of my tests run. (well, they ran before I tried using the namespace in `spec_helper`) because they obviously make reference to my namespace all over the place.

Can someone explain what's going on here? Also, where do people place helpers that use the same namespace defined in your app source js. I also tried making a `support` folder and doing a `require("./support/helpers.js");` but received some weird errors.

I'm basically trying to stub out an object that normally gets populated from a rails model.