2017-12-06 3 views
0

What's을 보낸 후 헤더를 설정할 수 없습니다?, 두 개의 오류를 유발 : 정의되지 않은 '_id'속성을 읽을 수 없습니다.BeforeEach, 오류 :</p> <p>오류 : 그들은</p>을 보낸 후 헤더를 설정할 수 없습니다 <p>형식 오류들이이 코드를 잘못

내가 생각하기 때문에 체인. 그때 BeforeEach에서,하지만 난 그것을 해결할 수 없다, 누군가 도울 수 있습니까?. 감사.

const expect = require('expect'); 
const request = require('supertest'); 
const{ObjectID} = require('mongodb'); 

const {app} = require('./../server'); 
const {Todo} = require('./../models/todo'); 

if(!module.parent) { 
app.listen(); 
} 

const todos=[{ 
    _id:new ObjectID(), 
    text:"2 test todo" 
}, 
{ 
_id:new ObjectID(), 
text:"1 test todo" 
}]; 

beforeEach((done) => { 
    Todo.remove({}).then(() => { 
    return Todo.insertMany(todos); 
    }).then(() => done()); 
}); 

describe('DELETE /todos/:id',() => { 
    it('most delete a doc', (done) => { 
    let hexId = todos[1]._id.toHexString(); 

    request(app) 
    .delete(`/todos/${hexId}`) 
    .expect(200) 
    .expect((res) => { 
     expect(res.body.todo._id).toBe(hexId); 
    }) 
    .end((err, res) => { 
     if(err) return done(err); 

    Todo.findById(hexId).then((todo) => { 
     expect(todo).toNotExist(); 
     done(); 
    }).catch((e) => done(e)); 

    }); 
    }); 
}); 

답변

0

오류 : 그들은

을 보낸 후 헤더를 설정할 수 없습니다 -> 콜백 (완료) 이미

형식 오류라는 이유는 정의의 속성을 읽을 수 없습니다 '_id'.

나는 형식 오류 라인 번호를 모르는 그러나 화면 주석 코드 아래에 있지만

beforeEach((done) => { 
    Todo.remove({}).then(() => { 
    return Todo.insertMany(todos); 
    }) 
    .then(() =>{ 
    describe('DELETE /todos/:id',() => { 
     it('most delete a doc', (done) => { 
     let hexId = todos[1]._id.toHexString(); 

     request(app) 
     .delete(`/todos/${hexId}`) 
     .expect(200) 
     .expect((res) => { 
       // make sure you are you getting from req.body 
      expect(res.body.todo._id).toBe(hexId); 
     }) 
     .end((err, res) => { 
      if(err) return done(err); 

     Todo.findById(hexId).then((todo) => { 
      expect(todo).toNotExist(); 
      done(); 
     }).catch((e) => done(e)); 

     }); 
     }); 
    }); 

});