-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.spec.js
50 lines (45 loc) · 1.35 KB
/
example.spec.js
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
/**
* Example API testing using Mocha and Supertest.
*/
/* eslint prefer-arrow-callback: off, func-names: off */
const request = require('supertest');
describe(
'For the API at https://jsonplaceholder.typicode.com the request',
function () {
/* Set up the base request to the API for reuse in tests. */
before(function () {
this.request = request('https://jsonplaceholder.typicode.com');
});
/* The specs for the /posts endpoint */
describe('/posts', function () {
this.endpoint = '/posts';
/* The specs for the GET verb */
describe('with GET', function () {
it('responds with json', function (done) {
this.request
.get('/posts')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, done);
});
});
/* The specs for the POST verb */
describe('with POST', function () {
this.data = {
title: 'My Post',
body: 'I love JSON.',
userId: 10,
};
it('responds with json', function (done) {
this.request
.post('/posts')
.type('application/json')
.send(this.data)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(201, done);
});
});
});
}
);