-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest.js
More file actions
51 lines (40 loc) · 1.19 KB
/
test.js
File metadata and controls
51 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const chai = require('chai');
const chaiHttp = require('chai-http');
const { expect } = chai;
const app = require('./render'); // Assuming your server code is in render.js
chai.use(chaiHttp);
describe('/render Endpoint Tests', () => {
let server;
before(async () => {
server = await app.listen(4000);
});
after(() => {
server.close();
});
it('should return an error if URL is missing', async () => {
const res = await chai.request(server)
.post('/render')
.send({});
expect(res).to.have.status(400);
expect(res.body).to.have.property('error');
});
it("Gives correct response", async () => {
const res = await chai.request(server)
.post('/render')
.send({
url: "https://example.com"
// headers: {'Accept': 'text/html; charset=utf-8; text/plain'}
});
expect(res).to.have.status(200);
expect(res.text).to.contain("<h1>Example Domain</h1>")
});
it('should handle errors gracefully', async () => {
const res = await chai.request(server)
.post('/render')
.send({
url: 'invalid-url'
});
expect(res).to.have.status(500);
expect(res.body).to.have.property('error');
});
});