I have tried everything there is to it but supertest keeps showing to set timeout to more than 2000ms and I have set it to 100000ms, but still it never works.
I have tried the async method, changing timeout, and alot methods.
I have attached my code below
if you need the whole code let me know i will share it.
I am using jest --watchAll for running the file
PS: thanks in advance
const request = require("supertest");
const dotenv = require("dotenv");
const app = require("../app");
const mongoose = require("mongoose");
const User = require("../models/user");
dotenv.config({ path: "../config.env" });
let conn;
const apiBaseUrl = "/api/v1";
beforeAll(async (done) => {
const url = "mongodb://localhost:27017/api-test";
conn = await mongoose.connect(url, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
useUnifiedTopology: true,
});
await User.create({
role: "admin",
firstName: "New",
lastName: "Admin",
email: "admin@someone.com",
password: "helloworld123",
airline: "air",
airlineId: "12345",
airlinePassword: "123",
});
await User.insertMany(require("./files/usersMockData.json"));
});
afterAll(async (done) => {
conn.connection.db.dropDatabase();
});
describe("User Module", (done) => {
let token;
let adminToken;
let randomUser;
// Normal User Functions
it("POST -> Create User", (done) => {
// Invalid Email
return request(app)
.post(`${apiBaseUrl}/users`)
.send({
email: "name@name",
password: "123",
airline: "SomeAirline",
airlineId: "12345",
airlinePassword: "123",
})
.expect(400, done);
});
// Invalid password less than 8 letter
it("POST -> Create User", (done) => {
return request(app)
.post(`${apiBaseUrl}/users`)
.send({
email: "name@gmail.com",
password: "123",
airline: "SomeAirline",
airlineId: "12345",
airlinePassword: "123",
})
.expect(400, doe);
});
// Invalid airline name from enum
it("POST -> Create User", (done) => {
return request(app)
.post(`${apiBaseUrl}/users`)
.send({
email: "name@gmail.com",
password: "somepass123",
airline: "SomeAirline",
airlineId: "12345",
airlinePassword: "123",
})
.expect(400, done);
});
// Working
it("POST -> Create User", (done) => {
return request(app)
.post(`${apiBaseUrl}/users`)
.send({
email: "airline@gmail.com",
password: "somepass123",
airline: "someair",
airlineId: "16957",
airlinePassword: "123",
})
.expect(201)
.then((res) => {
expect(res.body).toEqual(
expect.objectContaining({
status: expect.stringContaining("success"),
data: expect.objectContaining({
_id: expect.any(String),
email: expect.any(String),
airline: expect.any(String),
airlineId: expect.any(String),
}),
})
);
});
});
});