Skip to content

Instantly share code, notes, and snippets.

@ogra
Created September 16, 2016 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogra/2d880c83a7294aded77fed30ae99b27d to your computer and use it in GitHub Desktop.
Save ogra/2d880c83a7294aded77fed30ae99b27d to your computer and use it in GitHub Desktop.
"MEAN Web Development" p.267-269 for the latest version of Should.js (Array(), Object() instead of Array, Object)
var app = require('../../server.js'),
request = require('supertest'),
should = require('should'),
mongoose = require('mongoose'),
User = mongoose.model('User'),
Article = mongoose.model('Article');
var user, article;
describe('Articles Controller Unit Tests:', function() {
beforeEach(function(done) {
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: 'test@test.com',
username: 'username',
password: 'password'
});
user.save(function() {
article = new Article({
title: 'Article Title',
content: 'Article Content',
user: user
});
article.save(function(err) {
done();
})
});
});
describe('Testing the GET methods', function() {
it('Should be able to get the list of articles', function(done) {
request(app).get('/api/articles/')
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
res.body.should.be.an.Array().and.have.lengthOf(1);
res.body[0].should.have.property('title', article.title);
res.body[0].should.have.property('content', article.content);
done();
});
});
it('Should be able to get the specific article', function(done) {
request(app).get('/api/articles/' + article.id)
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200)
.end(function(err, res) {
res.body.should.be.an.Object().and.have.property('title', article.title);
res.body.should.have.property('content', article.content);
done();
});
});
});
afterEach(function(done) {
Article.remove().exec();
User.remove().exec();
done();
});
});
@ogra
Copy link
Author

ogra commented Sep 16, 2016

lines 41 and 55.

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