Permalink
Browse files

added tests for customHeaders

  • Loading branch information...
1 parent d57c4f5 commit 520d83bcde036576200cf8324e6b5ab598051921 @davidrapin committed Mar 26, 2012
Showing with 53 additions and 3 deletions.
  1. +48 −0 test/webpage-spec.js
  2. +5 −3 test/webserver-spec.js
View
@@ -75,6 +75,11 @@ describe("WebPage object", function() {
expect(page.settings).toNotEqual(null);
expect(page.settings).toNotEqual({});
});
+
+ expectHasProperty(page, 'customHeaders');
+ it("should have customHeaders as an empty object", function() {
+ expect(page.customHeaders).toEqual({});
+ });
checkViewportSize(page, {height:300,width:400});
@@ -207,6 +212,49 @@ describe("WebPage object", function() {
expect(fileName).toEqual('README.md');
});
});
+
+ it("should set custom headers properly", function() {
+ var server = require('webserver').create();
+ server.listen(12345, function(request, response) {
+ // echo received request headers in response body
+ response.write(JSON.stringify(request.headers));
+ response.close();
+ });
+
+ var url = "http://localhost:12345/foo/headers.txt?ab=cd";
+ var customHeaders = {
+ "Custom-Key" : "Custom-Value",
+ "User-Agent" : "Overriden-UA",
+ "Referer" : "Overriden-Referer",
+ };
+ page.customHeaders = customHeaders;
+
+ var handled = false;
+ runs(function() {
+ expect(handled).toEqual(false);
+ page.open(url, function (status) {
+ expect(status == 'success').toEqual(true);
+ handled = true;
+
+ var echoedHeaders = JSON.parse(page.plainText);
+ // console.log(JSON.stringify(echoedHeaders, null, 4));
+ // console.log(JSON.stringify(customHeaders, null, 4));
+
+ expect(echoedHeaders["Custom-Key"]).toEqual(customHeaders["Custom-Key"]);
+ expect(echoedHeaders["User-Agent"]).toEqual(customHeaders["User-Agent"]);
+ expect(echoedHeaders["Referer"]).toEqual(customHeaders["Referer"]);
+
+ });
+ });
+
+ waits(50);
+
+ runs(function() {
+ expect(handled).toEqual(true);
+ server.close();
+ });
+
+ });
});
describe("WebPage construction with options", function () {
View
@@ -32,9 +32,11 @@ function checkRequest(request, response) {
expect(request.method).toEqual("POST");
expect(request.hasOwnProperty('post')).toBeTruthy();
expect(typeof request.post).toEqual('object');
- console.log(JSON.stringify(request.post, null, 4));
- console.log(JSON.stringify(expectedPostData, null, 4));
- console.log(JSON.stringify(request.headersappl, null, 4));
+ expect(JSON.stringify(request.post, null, 4))
+ .toEqual(JSON.stringify(expectedPostData, null, 4));
+ // console.log(JSON.stringify(request.post, null, 4));
+ // console.log(JSON.stringify(expectedPostData, null, 4));
+ // console.log(JSON.stringify(request.headers, null, 4));
expect(request.post).toEqual(expectedPostData);
expect(request.hasOwnProperty('rawData')).toBeTruthy();
expect(typeof request.rawData).toEqual('object');

0 comments on commit 520d83b

Please sign in to comment.