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

const frisby = require('frisby');

// Do setup first
frisby.globalSetup({
  request: {
    headers: {
      'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),
      'Content-Type': 'application/json',
    }
  }
});

// Any global setup is automatically applied to every test
it ('uses globalSetup for every test after it is called', function () {
  return frisby
    .get('http://api.example.com')
    .expect('status', 200);
});

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

const frisby = require('frisby');

// The 'setup' function only affects a single test
it ('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);
});

Last updated