0

I am using sinon to create a mock but its methods are not getting restored after calling restore and when i again try to wrap them i get error. Here is what I am doing:-

describe(‘test suite’ , () => {
    describe('test suite',()=>{
        it('should do something',(done) => {
                 let mock =  sinon.mock('model').expects('findOne').chain('exec').yieldAsync(stuff);
            funcCall((err,response) => {
                mock.restore();
            })
         })
    })

    describe('test suite',()=>{
         it('should do something',(done) => {
                 let mock =  sinon.mock('model').expects('findOne').chain('exec').yieldAsync(stuff);
            funcCall((err,response) => {
                mock.restore();
            })
        })
    })
})

but i get findOne is already wrapped

Alex
  • 37,502
  • 51
  • 204
  • 332
vidit mathur
  • 62
  • 1
  • 2
  • 8
  • Can you verify the first test is completing succssfilly? Put a console loog just before 1st mock.restore(), if for whatever reason it doesn't hit it, will give you an error. Alternatively, you can try using a sandbox and put a sandbox.restore() in an afterEach clause. – Mankind1023 Mar 15 '18 at 15:24
  • @Mankind1023 first case works fine , and giving expected behaviour but the mock is still not getting restored – vidit mathur Mar 21 '18 at 02:58
  • @Mankind1023 yes that's what is happening – vidit mathur Apr 03 '18 at 03:26

0 Answers0