jeudi 26 février 2015

Where do I use Pretender to enable Ember Qunit integration tests with rails-csrf?

We are using rails-csrf in our ember-cli app. The README on rails-csrf says:



Be sure to mock out the call to the csrf server endpoint. Otherwise your tests will fail with


"error while processing route: [route]"


messages in the browser console. For example:




server = new Pretender(function() {
this.get('/csrf', function(request) {
return [200, {"Content-Type": "application/json"},
JSON.stringify({
"authenticity_token": "token"
})
];
});
});


I understand the problem here (our integration tests are indeed showing this error) and I understand how Pretender solves it. I've got Pretender installed via ember-cli-pretender.


What I don't understand is how this code snippet - configuration for a Pretender mock - should be included to be useful. Should it go in the setup hook of an integration test? (I've tried that, and it hasn't worked yet, but that doesn't mean it won't.) Should it go in tests/helpers/start-app.js along with the integration test setup?


I tried this, but it isn't working:



module('Integration test', {
setup: function() {
App = startApp();

var server = new Pretender(function() {
this.get('/csrf', function(request) {
return [200, {"Content-Type": "application/json"},
JSON.stringify({
"authenticity_token": "token"
})
];
});
});
},
teardown: function() {
Ember.run(App, App.destroy);
}
});


Or should we just be using ember-pretenderify? Does that handle this sort of case?


(This question is superficially similar to this older one, but the available tools for handling this in Ember have changed significantly.)





Aucun commentaire:

Enregistrer un commentaire