Answer the question
In order to leave comments, you need to log in
How to test functionality using Mocha?
I want to write the first test for the Mocha article comment system.
What is the testing methodology?
Scheme
var CommentSchema = new Schema({
created: {
type: Date,
default: Date.now
},
content: {
type: String,
default: '',
trim: true,
required: 'Content cannot be blank'
},
articleId: {
type: Schema.ObjectId,
ref: 'Article'
},
user: {
type: Schema.ObjectId,
ref: 'User'
}
});
user = new User({
firstName: 'Full',
lastName: 'Name',
displayName: 'Full Name',
email: '[email protected]',
username: credentials.username,
password: credentials.password,
provider: 'local'
});
user.save(function () {
article = {
title: 'Article Title',
content: 'Article Content'
};
comment = {
content: 'Article Comment',
articleID: article,
user: user
};
done();
});
Answer the question
In order to leave comments, you need to log in
See how it's done in node-express-mongoose-demo tests . True, there are rather integration tests, and not a unit, but the meaning is the same and approximately the same is checked.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question