Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
608108ee
...
608108eeef2fd29ebf739c61abf4a7a12181531c
authored
2013-02-25 01:23:08 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
request tests uses setUp() and tearDown()
1 parent
37e301ee
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
19 deletions
tests/suites/casper/request.js
tests/suites/casper/request.js
View file @
608108e
/*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
();
});
}
});
...
...
Please
register
or
sign in
to post a comment