-
-
Save anneKay/3aa558d3ccf03fec7ce7525e62c2ca7c to your computer and use it in GitHub Desktop.
import expect from 'expect'; | |
import request from 'supertest'; | |
import app from './../app'; | |
// Test for creating an article | |
describe ('POST api/articles', () => { | |
const article = { | |
title: 'the title', | |
body: '', | |
description: 'the description', | |
image: 'https://image.jpg' | |
} | |
it('should not create an article if body field is empty', (done) => { | |
request(app) | |
.post('api/articles') | |
.set('authentication', 'JWTtoken') | |
.send(article) | |
.expect(400) | |
.expect((res, err) => { | |
expect(res.body.error).toExist(); | |
expect(res.body.error[0].body.message).toBe('body field can not be empty'); | |
}) | |
.end(done); | |
}); | |
}); |
I think you should look into your expect statement. First I feel the HTTP error code should not be 200, given the fact that the request was not successfully created. ¡Chao!
Nice job on testing for when an article's description field is empty. Keep it up and reflect on more edge cases especially on the error message.
Nice work!, but I feel you can actually be specific on the expect(400)
so we will know that we are expecting a status code
of 400
.
Good job on your TDD, great initiative on thinking about the possible scenarios, I, however, think the error body should include a specific message pointing towards the body field being empty.
Nice attempt! You checked for empty body, I bet no user will be able to create an article without a body with this test case, that's fine, keep it up.
Good job testing for empty article body. This will ensure that an article cannot be created if the body is empty.