-
-
Save musonant/16a658223e016e2379286cba295923a7 to your computer and use it in GitHub Desktop.
| import chai, { expect } from 'chai'; | |
| import { describe, it } from 'mocha'; | |
| import chaiHttp from 'chai-http'; | |
| chai.use(chaiHttp); | |
| chai.should(); | |
| const newArticle = { | |
| title: 'Design patterns', | |
| body: 'There are several design patterns e.g: MVC pattern', | |
| description: 'List of most popular design patterns used in Javascript' | |
| }; | |
| describe('Test cases for Authors Haven app', () => { | |
| it('POST /articles/', (done) => { | |
| chai.request(app) | |
| .post('/api/articles') | |
| .send(newArticle) | |
| .end((err, res) => { | |
| res.should.have.status(201); | |
| res.body.should.be.a('object'); | |
| res.body.article.should.be.a('object'); | |
| res.body.article.id.should.be.a('number'); | |
| res.body.article.title.should.equal('Design patterns'); | |
| res.body.article.body.should.equal('There are several design patterns e.g: MVC pattern'); | |
| res.body.article.body.should.equal('List of most popular design patterns used in Javascript'); | |
| done(); | |
| }); | |
| }); | |
| }) | |
For the new line, I had to add an extra line (making two) before it could display. Who knows why?
I guess it's part of the nuances of this platform. It appears a line with no character keyed in is trimmed off. Therefore even space, tab or enter, can preserve a line, and let it show when you save.
Instead of hardcoding the expected values like you have done, to be on the safe side, you could use a reference to the original data you sent to the server i.e. res.body.article.title.should.equal('Design patterns') could be rewritten as res.body.article.title.should.equal(newArticle.title). This assertion as you have written it would fail if a single space or a character is mistakenly included in the hardcoded strings.
But the code is neatly written and clear
For the new line, I had to add an extra line (making two) before it could display. Who knows why?