Forked from Oloyedesinmiloluwa/createArticle.test.js
Last active
July 24, 2018 14:55
-
-
Save anneKay/3aa558d3ccf03fec7ce7525e62c2ca7c to your computer and use it in GitHub Desktop.
Fargo Team TDD activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice work!, but I feel you can actually be specific on the
expect(400)
so we will know that we are expecting astatus code
of400
.