我有一个如下所示的模块:
const config = require('config')
const isActive = config.get('isActive')
const infoMap = new Map()
const set = (key, value) => {
infoMap.set(key, value)
}
const get = (key) => infoMap.get(key)
module.exports={set, get}
以及我测试这些东西的测试:
let get
let set
beforeEach(() => {
jest.mock('config')
mockIsActive = require('config').get.mockReturnValueOnce(true)
get = require('../cache/mymap').get
set = require('../cache/mymap').set
})
describe('The map', () => {
describe('when data is added', () => {
set('testKey', "testData")
it('should contains the data', async () => {
const dataFromMap = get('testKey')
assert("testData", dataFromMap)
})
})
})
当使用以下命令调用时会失败set:
set is not a function
奇怪的是,它get运行起来没有问题。
慕尼黑8549860
相关分类