Skip to content

Commit edfdddd

Browse files
committed
test: fix errors
1 parent 9f8b394 commit edfdddd

File tree

5 files changed

+93
-146
lines changed

5 files changed

+93
-146
lines changed

__tests__/server/plural-fake.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ describe('Fake server', () => {
3434
request(server)
3535
.get('/posts/1/comments')
3636
.expect('Content-Type', /json/)
37-
.expect([db.comments[0], db.comments[1]])
38-
.expect(200))
37+
.expect(200, [db.comments[0], db.comments[1]]))
3938
})
4039

4140
describe('POST /:resource', () => {
@@ -46,8 +45,12 @@ describe('Fake server', () => {
4645
.expect('Access-Control-Expose-Headers', 'Location')
4746
.expect('Location', /posts\/3$/)
4847
.expect('Content-Type', /json/)
49-
.expect({ id: 3, body: 'foo', booleanValue: true, integerValue: 1 })
50-
.expect(201)
48+
.expect(201, {
49+
id: 3,
50+
body: 'foo',
51+
booleanValue: true,
52+
integerValue: 1,
53+
})
5154
assert.strictEqual(db.posts.length, 2)
5255
})
5356
})
@@ -61,8 +64,7 @@ describe('Fake server', () => {
6164
// body property omitted to test that the resource is replaced
6265
.send(post)
6366
.expect('Content-Type', /json/)
64-
.expect(post)
65-
.expect(200)
67+
.expect(200, post)
6668
// TODO find a "supertest" way to test this
6769
// https://github.com/typicode/json-server/issues/396
6870
assert.deepStrictEqual(res.body, post)
@@ -78,16 +80,15 @@ describe('Fake server', () => {
7880
.patch('/posts/1')
7981
.send(partial)
8082
.expect('Content-Type', /json/)
81-
.expect(post)
82-
.expect(200)
83+
.expect(200, post)
8384
assert.deepStrictEqual(res.body, post)
8485
assert.notDeepStrictEqual(db.posts[0], post)
8586
})
8687
})
8788

8889
describe('DELETE /:resource/:id', () => {
8990
test('should not destroy resource', async () => {
90-
await request(server).del('/posts/1').expect({}).expect(200)
91+
await request(server).del('/posts/1').expect(200, {})
9192
assert.strictEqual(db.posts.length, 2)
9293
})
9394
})

__tests__/server/plural-with-custom-foreign-key.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,15 @@ describe('Server with custom foreign key', () => {
3333
request(server)
3434
.get('/posts/1/comments')
3535
.expect('Content-Type', /json/)
36-
.expect([db.comments[0], db.comments[1]])
37-
.expect(200))
36+
.expect(200, [db.comments[0], db.comments[1]]))
3837
})
3938

4039
describe('GET /:resource/:id', () => {
4140
test('should respond with json and corresponding resource', () =>
4241
request(server)
4342
.get('/posts/1')
4443
.expect('Content-Type', /json/)
45-
.expect(db.posts[0])
46-
.expect(200))
44+
.expect(200, db.posts[0]))
4745
})
4846

4947
describe('GET /:resource?_embed=', () => {
@@ -54,8 +52,7 @@ describe('Server with custom foreign key', () => {
5452
return request(server)
5553
.get('/posts?_embed=comments')
5654
.expect('Content-Type', /json/)
57-
.expect(posts)
58-
.expect(200)
55+
.expect(200, posts)
5956
})
6057
})
6158

@@ -66,8 +63,7 @@ describe('Server with custom foreign key', () => {
6663
return request(server)
6764
.get('/posts/1?_embed=comments')
6865
.expect('Content-Type', /json/)
69-
.expect(post)
70-
.expect(200)
66+
.expect(200, post)
7167
})
7268
})
7369

@@ -80,8 +76,7 @@ describe('Server with custom foreign key', () => {
8076
return request(server)
8177
.get('/comments?_expand=post')
8278
.expect('Content-Type', /json/)
83-
.expect(comments)
84-
.expect(200)
79+
.expect(200, comments)
8580
})
8681
})
8782

@@ -92,8 +87,7 @@ describe('Server with custom foreign key', () => {
9287
return request(server)
9388
.get('/comments/1?_expand=post')
9489
.expect('Content-Type', /json/)
95-
.expect(comment)
96-
.expect(200)
90+
.expect(200, comment)
9791
})
9892
})
9993

@@ -103,8 +97,7 @@ describe('Server with custom foreign key', () => {
10397
.post('/posts/1/comments')
10498
.send({ body: 'foo' })
10599
.expect('Content-Type', /json/)
106-
.expect({ id: 4, post_id: '1', body: 'foo' })
107-
.expect(201))
100+
.expect(201, { id: 4, post_id: '1', body: 'foo' }))
108101
})
109102

110103
describe('DELETE /:resource/:id', () => {

0 commit comments

Comments
 (0)