Jest and SuperTest

JS
R
JavaScript

Example of a test

1/*
2   "test": "jest --forceExit --runInBand --coverage --watchAll",
3*/
4import supertest from 'supertest';
5import { apiEndpoint, authorization } from './configs';
6const request = supertest(`${apiEndpoint}/v1/api`);
7
8  it('Should create a new user , async () => {
9    return request
10      .post('/public/hub-users')
11      .send(createUserMock)
12      .set('Authorization', authorization)
13      .expect(200)
14      .then((response) => {
15        const { result } = response.body;
16        expect(result).toBeDefined();
17        if (result) {
18          userId = result._id;
19          expect(userId).toBeDefined();
20        }
21      });
22  });

Created on 4/15/2020