Skip to content

Commit a20968c

Browse files
committed
tests
1 parent ad866fc commit a20968c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
HTTPError,
3+
NotFoundError,
4+
BadRequestError,
5+
InternalServerError,
6+
createHTTPError
7+
} from '../src';
8+
9+
describe('http-errors', () => {
10+
it('should create a NotFoundError with correct properties', () => {
11+
const error = new NotFoundError();
12+
13+
expect(error).toBeInstanceOf(HTTPError);
14+
expect(error).toBeInstanceOf(Error);
15+
expect(error.status).toBe(404);
16+
expect(error.message).toBe('Not Found | Status: 404');
17+
expect(error.name).toBe('NotFoundError');
18+
});
19+
20+
it('should create a BadRequestError with correct properties', () => {
21+
const error = new BadRequestError();
22+
23+
expect(error.status).toBe(400);
24+
expect(error.message).toBe('Bad Request | Status: 400');
25+
});
26+
27+
it('should create an InternalServerError with correct properties', () => {
28+
const error = new InternalServerError();
29+
30+
expect(error.status).toBe(500);
31+
expect(error.message).toBe('Internal Server Error | Status: 500');
32+
});
33+
34+
it('should create errors using createHTTPError', () => {
35+
const notFoundError = createHTTPError(404);
36+
expect(notFoundError).toBeInstanceOf(NotFoundError);
37+
expect(notFoundError.status).toBe(404);
38+
39+
const badRequestError = createHTTPError(400);
40+
expect(badRequestError).toBeInstanceOf(BadRequestError);
41+
expect(badRequestError.status).toBe(400);
42+
});
43+
44+
it('should create a generic HTTPError for unknown status codes', () => {
45+
const error = createHTTPError(999);
46+
47+
expect(error).toBeInstanceOf(HTTPError);
48+
expect(error.status).toBe(999);
49+
expect(error.message).toBe('Unknown Error | Status: 999');
50+
});
51+
});

0 commit comments

Comments
 (0)