Node.js module to encapsulate Jest testing helpers (backend)
npm install @apolitical/testingNode.js module to encapsulate Jest testing helpers (backend)
Requires the following to run:
- [node.js][node] 16.13.0+
- [yarn][yarn]
[node]: https://nodejs.org/en/download/
[yarn]: https://classic.yarnpkg.com/en/docs/install
Install with yarn:
``sh`
yarn add -D @apolitical/testing
First of all, include @apolitical/testing module:
``
const apoliticalTesting = require('@apolitical/testing');
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:
- loggedInloggedOut
- loggedInAdmin
- loggedInMyself
-
The loggedInMyself agent can also be updated with custome token payload with the use of the assignTokenToMyself` function.