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 (done) {
  frisby.
    .get('http://api.example.com')
    .expect('status', 200)
    .done(done);
});

setup(options)

The setup method is similar to globalSetup, but it only affects a single specific test that it is attached to.

Usage Examples

const frisby = require('frisby');

// The 'setup' function only affects a single test
it ('runs setup only for a single test', function (done) {
  frisby.
    .get('http://api.example.com')
    .setup({
      request: {
        headers: {
          'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64')
        }
      }
    })
    .expect('status', 200)
    .done(done);
});

results matching ""

    No results matching ""