몽구스 모델을 jest
으로 모의하려고하는데, Cannot create property 'constructor' on number '1'
오류가 발생합니다. 아래에 표시된 두 개의 파일로 프로젝트를 생성하여 문제를 재현 할 수있었습니다. 몽구스 모델을 jest
으로 조롱하는 방법이 있습니까?몽구스 몽구스 모델 조롱
이 ./model.js
const mongoose = require('mongoose')
const Schema = mongoose.Schema
const schema = new Schema({
name: String
})
module.exports = mongoose.model('Test', schema)
./model.test.js
jest.mock('./model')
const Test = require('./model')
// Test.findOne.mockImplementation =() => {
// ...
// }
오류 :
는FAIL ./model.test.js
● Test suite failed to run
TypeError: Cannot create property 'constructor' on number '1'
at ModuleMockerClass._generateMock (../../jitta/sandbox/rest_api/node_modules/jest-mock/build/index.js:458:34)
at Array.forEach (native)
at Array.forEach (native)
at Array.forEach (native)
업데이트 :
는 것 같다 농담에 벌레. 내가이 문제를 해결하기 위해이 패키지를 작성할 수 있도록 https://github.com/facebook/jest/issues/3073
농담에 대해서는 잘 모르겠지만 [mockgoose] (https://github.com/mockgoose/mockgoose)는 모든 것을 조롱하려고하는 것보다 쉬운 선택이었습니다. – Matt