模拟其他模块会重置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 (将#修改为@)