Category : supertest

I am trying to build a test package to test an API already deployed, how can I pass the url? Here is an example: const request = require("supertest"); const app = "https://backend.dev.co.mz"; describe("Test the root path", () => { test("It should response the GET method", async () => { const response = await request(app).get("/"); expect(response.statusCode).toBe(200); ..

Read more

I’m currently taking a Node.js Course online and have to do the integration tests required to complete it before deployment. I just tested the GET and POST method and succeeded, however I’m struggling with the PUT method test. I’m using the exact same code the instructor provided for it, but I keep getting the error ..

Read more

I’m running an app built with NestJS. I have integration tests written with the supertest library. I’m using Jest as my testing framework / test runner. My integration tests look like this. describe(‘Item controller’, () => { beforeAll(async () => { const moduleRef = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleRef.createNestApplication(); await app.init(); test(‘/Delete ..

Read more

I’m trying to test my users endpoint using supertest : router.post("/users", async (req, res) => { const user = new User(req.body); try { await user.save(); const token = await user.generateAuthToken(); res.status(201).send({ user: user, token: token }); } catch (e) { res.status(400).send(e); } }); My user.test.js look like so : const request = require("supertest"); const app ..

Read more

I have the following simple API get request using supertest javascript library: getUsers(){ request.get(`users?access-token=${TOKEN}`) .end((err, res)=>{ console.log(err) console.log(res.body) }); } and this is my test using it: describe(‘Users’, ()=>{ const lm = new LoginModule(); it(‘GET /users’, (done)=>{ // lm.login(<MAIL_VAR>, <PASSWORD>, "daniel"); var res = lm.getUsers() console.log(res); done(); }); }); I want to return the response ..

Read more

I would like to change the following async/await code const mongoose = require(‘mongoose’) const supertest = require(‘supertest’) const app = require(‘../app’) const api = supertest(app) test("total number of blogs", async () => { const response = await api.get(‘/api/blogs’) expect(response.body).toHaveLength(1) }) afterAll(() => { mongoose.connection.close() }) to a Promise like this: const mongoose = require(‘mongoose’) const ..

Read more