Skip to content

Instantly share code, notes, and snippets.

@Lumexralph
Last active July 24, 2018 14:49
Show Gist options
  • Save Lumexralph/2680ed1384fa9a246ee5ea482c08d518 to your computer and use it in GitHub Desktop.
Save Lumexralph/2680ed1384fa9a246ee5ea482c08d518 to your computer and use it in GitHub Desktop.
import expect from 'expect';
import request from 'supertest';
import app from '../app'; // the web server
const mockData = {
"article": {
"title": "",
"description": "Ever wonder how?",
"body": "You have to believe",
"tagList": ["reactjs", "angularjs", "dragons"]
}
}
describe('POST /api/articles create an article', () =>{
it('should not create the article when title is empty', (done) => {
request(app)
.post('/api/articles')
.send(mockdata)
.expect(400)
.expect(res => {
expect(res.body).toHaveProperty('errors');
expect(res.body.errors.body.length).toBe(1);
expect(res.body.errors.body[0]).toBe('can\'t be empty');
})
.end(done);
}
});
@OKiMaureen
Copy link

Good job on your TDD, great initiative on thinking about the possible scenarios.

@klevamane
Copy link

Creating an article without a title will be impossible to generate a slug. Good job providing a test that ensures that the article should not be created if the title property is empty.

@anneKay
Copy link

anneKay commented Jul 23, 2018

Great job on taking the initiative to add a test to check for title property before creating an article, this will ensure that an article does not get created with an incomplete data.

@ascii-dev
Copy link

Great one. One little something though, imports come first :P.

@veeqtor
Copy link

veeqtor commented Jul 23, 2018

Nice work!, Well laid out. Kudos.

@Oloyedesinmiloluwa
Copy link

Nice one! You checked for an empty title, I bet no user will be able to create an article without a title with this test, that's fine, keep it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment