Skip to content

Instantly share code, notes, and snippets.

@anneKay
Forked from Oloyedesinmiloluwa/createArticle.test.js
Last active July 24, 2018 14:55
Show Gist options
  • Save anneKay/3aa558d3ccf03fec7ce7525e62c2ca7c to your computer and use it in GitHub Desktop.
Save anneKay/3aa558d3ccf03fec7ce7525e62c2ca7c to your computer and use it in GitHub Desktop.
Fargo Team TDD activity
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);
});
});
@OKiMaureen
Copy link

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.

@Oloyedesinmiloluwa
Copy link

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