Commit 608108ee 608108eeef2fd29ebf739c61abf4a7a12181531c by Nicolas Perriault

request tests uses setUp() and tearDown()

1 parent 37e301ee
/*global casper*/
/*jshint strict:false*/
var currentRequest;
function onResourceRequested(request) {
currentRequest = request;
}
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");
casper.test.begin('requests tests', 3, {
setUp: function() {
casper.on('page.resource.requested', onResourceRequested);
},
function(request) {
test.assert(request.headers.some(testHeader),
"Casper.open() can set a custom header");
tearDown: function() {
currentRequest = undefined;
casper.removeListener('page.resource.requested', onResourceRequested);
},
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);
test: function(test) {
casper.start('tests/site/index.html', function() {
test.assertNot(currentRequest.headers.some(testHeader),
"Casper.open() sets no custom header by default");
});
casper.start('tests/site/index.html');
casper.thenOpen('tests/site/index.html', {
headers: {
Accept: 'application/json'
}
}, function() {
test.assert(currentRequest.headers.some(testHeader),
"Casper.open() can set a custom header");
});
casper.thenOpen('tests/site/index.html');
casper.thenOpen('tests/site/index.html', function() {
test.assertNot(currentRequest.headers.some(testHeader),
"Casper.open() custom headers option is not persistent");
});
casper.run(function() {
this.removeAllListeners('page.resource.requested');
test.done();
});
}
});
......