如何解决模拟其他模块会重置JEST中的前一个模块
我对模拟模块有一个奇怪的问题。我有一个模拟两个模块的测试文件:
- 猫鼬模型(导出的mongoose.model())
- 整个猫鼬模块
现在,当我添加console.log并登录UserModel时,当我评论jest.mock('mongoose')
时它将打印未定义的BUT,但它将正常工作。是什么原因呢?那是因为UserModel还导入了mongoose
吗?
import UserModel from '../../models'
jest.mock('../../models')
jest.mock('mongoose') // when I comment it,console log below,works OK. If not,it will print undefined
describe('like profile',() => {
it('should user id be present in likes in liked user',async () => {
console.log(UserModel) // prints undefined
})
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。