Papupata Documentation

API Reference

module supertestInvoker

Default export invokeSupertest

Purpose

This module allows you to use supertest to make papupata API requests, while gaining access to the actual supertest request for things like setting up headers and making detailed assertions on the response.

Availability

This functionality is available from papupata version 1.5.0 onwards.

Usage

import invokeSupertest from 'papupata/invokers/supertest'

To begin with, you'll want to set up a supertest request for your express application. Once done, you can create a supertest papupata adapter to start making API calls.

Do note that you'll almost certainly want to configure papupata with a blank base URL to make things work.

Parameters

NameTypeDescription
supertestRequestSupertest requestSupertest request
apiDeclaredAPIThe papupata API you wish to invoke
argsObjectThe arguments to the API call, just as you'd pass to the API call normally.

Returns

Papupata MakeRequestAdapter

Examples

import { APIDeclaration } from 'papupata'
import invokeSupertest from 'papupata/invokers/supertest'
import express from 'express'
import supertest from 'supertest'

const app = express()
const request = supertest(app)
const API = new APIDeclaration()
API.configure({
  app,
  baseURL: ''
})
const api = API.declareGetAPI('/:id').params({id: String}).response<string>

const req = invokeSupertest(request, api, {id: 'foo'})
await req.expect(200)