【发布时间】:2017-01-07 17:27:22
【问题描述】:
我有 mocha、sinon 和 chai 的测试服:
describe('general visor methods tests', () => {
let res, req, next, resSpy, resNext;
beforeEach(() => {
res = {};
next = () => {};
resSpy = res.json = sinon.spy();
resNext = next = sinon.spy();
});
afterEach(() => {
resSpy.restore();
resNext.reset();
});
describe('get basemap layers from owner model', () => {
it('should send the basemap provided by the owner model', () => {
owner.basemap = ['basemap1', 'basemap2'];
getBaseMapLayersFromConfig(req, res, next);
// console.log(resSpy.args[0][0].data);
expect(resSpy.calledOnce).to.eql(true);
expect(resSpy.args[0][0].message).to.eql('basemaps correctly found');
expect(resSpy.args[0][0].data).to.eql(['basemap1', 'basemap2']);
});
...
如果我输入resSpy.reset() 它工作正常。我读过reset()函数是为了重置spy的状态。
但我不明白的是,如果我放 resSpy.restore() 那么它会抛出下一个错误:
TypeError: resSpy.restore is not a function
我不知道我做错了什么,也不知道使用恢复的正确方法是什么。
我也不知道什么时候应该使用重置或恢复。
【问题讨论】:
标签: javascript unit-testing mocha.js sinon chai