LearnBoost / tobi

Tobi: Expressive server-side functional testing with jQuery
408 stars 33 forks source link

Headers should be defaulted #36

Open samyakbhuta opened 13 years ago

samyakbhuta commented 13 years ago

https://github.com/LearnBoost/tobi/blob/master/lib/browser.js#L130

Currently there is no way the header's are defaulted. Guess it would be nice that there is a way to set some headers that are anyway expected by many of the server side code (e.g. express.js) like already done at https://github.com/LearnBoost/tobi/blob/master/lib/browser.js#L158. The other day tobi simulated POST request couldn't find req.body in the express.js middleware as headers['Content-type'] = 'application/json'; was missing.

Also, neither README nor the blogpost like this http://vilimpoc.org/blog/2011/01/19/testing-rest-api-with-learnboosts-tobi-vows-js/ specifies such necessity of setting the headers.

tj commented 13 years ago

browser.get('/login', { headers: { ... }}, function(res, $){ etc. how would you expect them to be defaulted? you want it to guess that it's json? not sure I get what you mean

tastapod commented 13 years ago

It's easy enough in an explicit browser.get or browser.post to set headers, but I can't set headers in the GET that occurs on a browser.click, for instance.

I'd like to be able to default the browser to always send Accept: text/html (unless I explicitly override it in an individual GET) but right now I can't.

hudgins commented 12 years ago

Similarly, you can't set the headers for a POST that happens as the result of a $('form').submit(). I'm using tobi with a system that creates a separate set of database tables namespaced by the virtual host. In testing on localhost, I set the host header to 'test' for each call to take advantage of this and segregate the test data. Works, except for the POST on submit(). What's the right solution here? Carry the host header in a browser.get/post/etc on to any subsequent requests?