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.
const frisby = require('frisby');// Do setup firstfrisby.globalSetup({request: {headers: {'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),'Content-Type': 'application/json',}}});// Any global setup is automatically applied to every testit ('uses globalSetup for every test after it is called', function () {return frisby.get('http://api.example.com').expect('status', 200);});
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.
const frisby = require('frisby');// The 'setup' function only affects a single testit ('runs setup only for a single test', function () {return frisby.setup({request: {headers: {'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64')}}}).get('http://api.example.com').expect('status', 200);});