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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
30 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"
);
},
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
.
test
.
begin
(
'requests tests'
,
3
,
{
setUp
:
function
()
{
casper
.
on
(
'page.resource.requested'
,
onResourceRequested
);
},
casper
.
on
(
'page.resource.requested'
,
function
(
request
)
{
tests
[
current
++
](
request
);
});
tearDown
:
function
()
{
currentRequest
=
undefined
;
casper
.
removeListener
(
'page.resource.requested'
,
onResourceRequested
);
},
casper
.
start
(
'tests/site/index.html'
);
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
.
thenOpen
(
'tests/site/index.html'
,
{
headers
:
{
Accept
:
'application/json'
}
});
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
();
});
casper
.
run
(
function
()
{
this
.
removeAllListeners
(
'page.resource.requested'
);
test
.
done
();
});
}
});
...
...
Please
register
or
sign in
to post a comment