How to use the request function from chai

Find comprehensive JavaScript chai.request code examples handpicked from public code repositorys.

16
17
18
19
20
21
22
23
24
25
it('Verificando se um usuário é registrado com sucesso', async () => {
    sinon.stub(User, 'create').resolves(mockRegister)
    sinon.stub(jwt, 'sign').onFirstCall().returns(mockToken);
    sinon.stub(User, 'findOne').onFirstCall().resolves(undefined).onSecondCall(undefined);

    let chaiHttpResponse = await chai.request(app).post('/register').send({
        name: "Scooby Doo",
        email: "scoobydoo@gmail.com",
        password: "senhaforte123",
        role: "customer"
fork icon0
star icon1
watch icon1

+ 7 other calls in file

20
21
22
23
24
25
26
27
28
29
    });

it('Verificando se o login foi realizado com sucesso', async () => {
    sinon.stub(User, 'findOne').resolves(mockUser)

    let chaiHttpResponse = await chai.request(app).post('/login').send({
        email: 'grupoalegria@gmail.com',
        password: 'senhamock'
    })
    expect(chaiHttpResponse.status).to.be.equal(200);
fork icon0
star icon1
watch icon1

+ 15 other calls in file

214
215
216
217
218
219
220
221
222
  };
  spendingLimit = await SpendingLimit.create({...SPENDING_LIMIT, userId: user._id, category: category._id});
});

it("should require a logged in user", async() => {
  const res = await chai.request(app)
    .get("/api/limit/");
  assertError(res, 401);
});
fork icon0
star icon0
watch icon4

+ 71 other calls in file

4
5
6
7
8
9
10
11
12
13
14
15
const UserFixture = require('../fixtures/user');
const { verifyJWT } = require('../../utils/common/auth');


chai.use(chaiHttp);
chai.should();
const request = chai.request;


describe('auth', function () {
  describe('Login', function () {
    before(async function () {
fork icon0
star icon0
watch icon1

+ 2 other calls in file

43
44
45
46
47
48
49
50
51
52
it('should authenticate user with valid credentials', (done) => {
  const userData = {
    "userName": user.userName,
    "userPassword": user.userPassword
  }
  chai.request(app)
    .post('/api/v1/userLogin')
    .send(userData)
    .end((err, res) => {
      if(res.body.accessToke)
fork icon0
star icon0
watch icon0

+ 4 other calls in file

28
29
30
31
32
33
34
35
36
37
});

// test get route
describe("GET /cars", () => {
    it("It should get all cars", (done) => {
        chai.request(server)
            .get("/cars")
            .end((err, res) => {
                res.should.have.status(200);
                res.body.should.be.a('array');
fork icon0
star icon0
watch icon0