测试时无法模拟变量

问题描述 投票:0回答:1

我正在尝试在节点js上进行测试,我想模拟将要进行单元测试的函数之外的变量。例如

const sample = [];
function uploadDoc {
sample.push('fileLocation')
}
function toSave(){
for (i=0;i<sample.length;i++)
**some process read and access doc
}

我在对第二个功能进行单元测试时遇到问题我已经尝试重新连接npm,但也无法正常工作

node.js testing mocha chai sinon
1个回答
0
投票
const sample = [];
    function uploadDoc {
    sample.push('fileLocation')
}
function toSave(){
    uploadDoc();
    for (var i=0;i<sample.length;i++)
    **some process read and access doc
}

Programming likes this will work,You should call uploadDoc firstly;
© www.soinside.com 2019 - 2024. All rights reserved.