F
F
Frisby
Search…
Introduction
Introduction
Frisby.js Overview
Getting Started
API and Usage
HTTP Request Methods
globalSetup() / setup()
Running Assertions
Nested Tests
Inspectors
File Uploads
Powered By
GitBook
globalSetup() / setup()
globalSetup(options)
Set any global parameters, headers, etc. that need to be sent with each HTTP request that Frisby sends out.
Most people use this for global headers, authentication, cookies, etc.
Usage Examples
Headers
1
const
frisby
=
require
(
'frisby'
);
2
3
// Do setup first
4
frisby
.
globalSetup
({
5
request
:
{
6
headers
:
{
7
'Authorization'
:
'Basic '
+
Buffer
.
from
(
"username:password"
).
toString
(
'base64'
),
8
'Content-Type'
:
'application/json'
,
9
}
10
}
11
});
12
13
// Any global setup is automatically applied to every test
14
it
(
'uses globalSetup for every test after it is called'
,
function
()
{
15
return
frisby
16
.
get
(
'http://api.example.com'
)
17
.
expect
(
'status'
,
200
);
18
});
Copied!
setup(options)
The
setup
method is similar to
globalSetup
, but it only affects a single specific test that it is attached to.
NOTE: The
setup
call MUST COME BEFORE calls to
get
,
post
,
fetch
, etc.
Usage Examples
1
const
frisby
=
require
(
'frisby'
);
2
3
// The 'setup' function only affects a single test
4
it
(
'runs setup only for a single test'
,
function
()
{
5
return
frisby
6
.
setup
({
7
request
:
{
8
headers
:
{
9
'Authorization'
:
'Basic '
+
Buffer
.
from
(
"username:password"
).
toString
(
'base64'
)
10
}
11
}
12
})
13
.
get
(
'http://api.example.com'
)
14
.
expect
(
'status'
,
200
);
15
});
Copied!
API and Usage - Previous
HTTP Request Methods
Next - API and Usage
Running Assertions
Last modified
2yr ago
Copy link
Contents
globalSetup(options)
Usage Examples
setup(options)
Usage Examples