i have problem testing my project with jasmine the error above shows in my specs i tried to solve it by adding done but it doesn't work and tried to extend jasmine time out by adding beforeEach with the timeout setting but doesnt work it is waiting till the time end and gives the same error the project is testing endpoints that have sql models and i am testing the models it self too
Note: the error is random meaning when i update any file the error goes to another spec and the errored spec passes when trying to run the errored spec individually by adding f before the spec the spec passes
all endpoints tested by postman and work correctly
**this one of the express handlers that i am testing and it's model down **
import supertest from 'supertest';
import app from '../../server';
import { testuser } from './userhandlerSpec';
const test = supertest(app);
describe('Testing order route =>', (): void => {
it('expect create to return http code 401', async (): Promise<void> => {
const create = await test.post('/order/user/1');
expect(create.status).toBe(401);
});
it('expect index to return http code 401', async (): Promise<void> => {
const index = await test.get('/order');
expect(index.status).toBe(401);
});
it('expect index to return http code 200', async (): Promise<void> => {
const token = await (await test.post('/user').send(testuser)).body;
const index = await test
.get('/order')
.set('Authorization', 'bearer ' + token);
expect(index.status).toBe(200);
});
it('expect show to return http code 401', async (): Promise<void> => {
const show = await test.get('/order/:order_id/user/:user_id');
expect(show.status).toBe(401);
});
it('expect show to return http code 200', async (): Promise<void> => {
const token = await (await test.post('/user').send(testuser)).body;
const show = await test
.get('/order/:order_id/user/:user_id')
.set('Authorization', 'bearer ' + token);
expect(show.status).toBe(200);
});
it('expect addProduct to return http code 401', async (): Promise<void> => {
const addProduct = await test.post('/order/:id/product');
expect(addProduct.status).toBe(401);
});
});
**this is the model **
import {
orderData,
ordersMethods,
order_productData,
} from '../../models/orderesmodel';
const test = new ordersMethods();
describe('Testing orders model =>', (): void => {
it('Testing output of index method', async (): Promise<void> => {
expect(await test.index(1)).toEqual([
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
{ order_id: 1, product_id: 1, quantity: 5, user_id: 1, status: 'active' },
]);
});
it('Testing output of create method', async (): Promise<void> => {
const o: orderData = {
user_id: '1',
status: 'active',
};
expect(await test.create(o)).toEqual({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
id: 2,
user_id: 1,
status: 'active',
});
});
it('Testing output of show method', async (): Promise<void> => {
expect(await test.show(1, 1)).toEqual([
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
{ order_id: 1, product_id: 1, quantity: 5, user_id: 1, status: 'active' },
]);
});
it('Testing output of addProduct method', async (): Promise<void> => {
const p: order_productData = {
product_id: '1',
quantity: '5',
order_id: '1',
};
expect(await test.addProduct(p)).toEqual({
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
id: 1,
product_id: 1,
quantity: 5,
order_id: 1,
});
});
});
Testing result
Testing users model =>
√ Testing output of show method
√ Testing output of index method
√ Testing output of create and authentication method
Testing server main Route
√ homePage error
√ should give http status code 200 and text(Hello World!)
Testing products model =>
√ Testing output of create method
√ Testing output of show method
√ Testing output of index method
Testing product route =>
√ expect show to return http code 200
√ expect index to return http code 200
√ expect create to return http code 401
Testing orders model =>
√ Testing output of addProduct method
√ Testing output of show method
√ Testing output of create method
√ Testing output of index method
Testing user route =>
√ expect create to return http code 401
√ expect auth to return http code 400
√ expect index to return http code 200
√ expect show to return http code 200
√ expect index to return http code 401
√ expect show to return http code 401
Testing order route =>
√ expect index to return http code 401
√ expect create to return http code 401
√ expect show to return http code 401
× expect show to return http code 200
- Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
× expect index to return http code 200
- Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
√ expect addProduct to return http code 401