I have a test suit with mocha, sinon and 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']);
});
...
if I put resSpy.reset()
it works fine. I've read that the reset() function is to reset the state of the spy.
But what i don't understand is that if i put resSpy.restore() then it thows the next error:
TypeError: resSpy.restore is not a function
I don't know what I'm doing wrong or what should be the correct way of using restore.
Also I don't quite know when should i use reset or restore.
Aucun commentaire:
Enregistrer un commentaire