unit-testingvuejs2chaikarma-mocha

Vue unit test error: expected [Function: proxy] to be false


Vue unit test error: expected [Function: proxy] to be false

The function in the Vue component is:

data(){
   return{
      showcart:false
   }
}

methods:{
   closedialoguebox: function() {
      return (this.showcart = false);
   }
}

and the unit test case for the respective function is:

it('closedialoguebox function should close the dialogue box when clicked on home', () => {

const Mockedshowcart = false
const someStub = sinon.stub(wrapper.vm,'closedialoguebox').returns(Mockedshowcart)
expect(someStub).to.be.false

}) }

and the error i'm getting is :

× closedialoguebox function should close the dialogue box when clicked on home
    expected [Function: proxy] to be false

Thanks in advance


Solution

  • someStub is a function that returns false. Your test case is not calling the function someStub. Add the parentheses to call the function. The correct statement is:

    expect(someStub()).to.be.false