request.js
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*global casper*/
/*jshint strict:false*/
function testHeader(header) {
return header.name === 'Accept' && header.value === 'application/json';
}
casper.test.begin('requests tests', 3, function(test) {
var current = 0,
tests = [
function(request) {
test.assertNot(request.headers.some(testHeader),
"Casper.open() sets no custom header by default");
},
function(request) {
test.assert(request.headers.some(testHeader),
"Casper.open() can set a custom header");
},
function(request) {
test.assertNot(request.headers.some(testHeader),
"Casper.open() custom headers option is not persistent");
}
];
casper.on('page.resource.requested', function(request) {
tests[current++](request);
});
casper.start('tests/site/index.html');
casper.thenOpen('tests/site/index.html', {
headers: {
Accept: 'application/json'
}
});
casper.thenOpen('tests/site/index.html');
casper.run(function() {
this.removeAllListeners('page.resource.requested');
test.done();
});
});