We currently have Jasmine tests for AngularJS running in our Ruby on Rails application. With that, we use VCR to generate API JSON files with fake data.
Would it be possible to embed those files into our JavaScript unit tests?
assets
since it should be excluded in production code.Our current structure looks like this:
spec/controllerSpec.js
scope.user.handleUserLoaded({
"is_logged_in": true,
"preferred_name": "Christian"
});
expect(scope.user.isAuthenticated()).toBeTruthy();
fixtures/fake_data/user.json
{
"is_logged_in": true,
"preferred_name": "Christian"
}
Instead of doing this duplication, we would prefer to have some kind of include into the JavaScript:
scope.user.handleUserLoaded(<% include "fixtures/fake_data/user.json" %>);
expect(scope.user.isAuthenticated()).toBeTruthy();
What would be the best way to do this?
We can definitely move files around, use .js.erb
files or try a different approach.