-
[ERROR] Uncaught TypeError: Cannot read property 'equal' of undefined개발/JS 2018. 7. 9. 21:39
TDD 테스트 코드 작성 중 [ERROR] Uncaught TypeError: Cannot read property 'equal' of undefined와 같은 에러를 발견했다.
var superagent = require('superagent')
var expect = require('expect')
describe('express rest api server', function(){
var id
it('post object', function(done){
superagent.post('http://localhost:3000/collections/test')
.send({
name: 'John',
email: 'john@naver.com'
})
.end(function(e, res) {
expect(e).to.equal(null) //에러객체는 null이여야한다.
expect(res.body.ops.length).to.equal(1) //응답 바디 배열은 한 가지 아이템만 가져야한다.
expect(res.body.ops[0]._id.length).to.equal(24) //첫 응답 본문 아이템은 24길이의 문자형태인 _id를 가져야한다.
id = res.body.ops[0]._id //새로 생성된 객체의 id를 전역변수에 저장해 조회, 변경, 삭제에 이용가능
done()
})
})
})
해당 모듈의 버전은.
"devDependencies": {
"expect": "^23.3.0",
"mocha": "^5.2.0",
"superagent": "^3.8.3"
}
해결)
문법이 잘못되었다.
expect(e).to.equal(null) 이 부분을
expect(e).toEqual(null)로 바꾸니 정상적으로 실행된다.
https://jest-bot.github.io/jest/docs/expect.html#toequalvalue
'개발 > JS' 카테고리의 다른 글
[ERROR]GET http://localhost/socket.io/?EIO=3&transport=polling&t=MIEj9iB 0 () (1) 2018.07.12 [Mongo] 간단한 몽고DB 명령어 (0) 2018.07.09 [ERROR] mongoskin에서 TypeError: Cannot read property 'apply' of undefined (0) 2018.06.25 [error] Failed to load c++ bson extension, using pure JS version (0) 2018.06.24 [npm] Working with package.json (0) 2018.04.16