@apolitical/testing

Node.js module to encapsulate Jest testing helpers (backend)

Usage no npm install needed!

<script type="module">
  import apoliticalTesting from 'https://cdn.skypack.dev/@apolitical/testing';
</script>

README

Apolitical Testing

Node.js module to encapsulate Jest testing helpers (backend)

Requirements

Requires the following to run:

Installation

Install with yarn:

yarn add -D @apolitical/testing

Usage

First of all, include @apolitical/testing module:

const apoliticalTesting = require('@apolitical/testing');

Request

The recommended way to use request helper is first by creating an instance with the session secret to encode the JWT tokens:

const instance = apoliticalTesting.request({ sessionSecret: 'hello' });

Then, you can use your express app to generate supertests agents:

const agents = instance.generateAgents(app);

The agents are:

  • loggedIn
  • loggedOut
  • loggedInAdmin
  • loggedInMyself

The loggedInMyself agent can also be updated with custome token payload with the use of the assignTokenToMyself function.