udemy-node-todo-app/server/tests/server.test.js

36 lines
798 B
JavaScript
Raw Normal View History

2017-11-30 04:15:25 +00:00
const expect = require('expect');
const request = require('supertest');
const {app} = require('./../server');
const {Todo} = require('./../models/todo');
beforeEach((done) => {
Todo.remove({}).then(() => done());
});
describe('POST /todos', () => {
it('should create a new todo', (done) => {
var text = 'X GON GIVE IT TO YA';
request(app)
.post('/todos')
.send({text})
.expect(200)
.expect((res) => {
expect(res.body.text).toBe(text);
})
.end((err, res) => {
if (err){
console.log(err);
return done(err);
}
Todo.find().then((todos) => {
expect(todos.length).toBe(1);
expect(todos[0].text).toBe(text);
})
done();
}).catch((err) => done(err))
});
});