Last active
March 20, 2019 00:56
-
-
Save musonant/16a658223e016e2379286cba295923a7 to your computer and use it in GitHub Desktop.
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 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(); | |
}); | |
}); | |
}) | |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.