Created
September 16, 2016 11:41
-
-
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)
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
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(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lines 41 and 55.