[Vuejs]-How to cover ajax calls in jest code coverage

0๐Ÿ‘

โœ…

I resolved the above problem with following test case

test(`getZipcode method`, () => {
    var res = { data: { zipCode: '72015' } }
    const mockAjax = sinon.stub(window.ajax, 'get').callsArgWith(2, res)
    wrapper.vm.getZipcode('city')
    sinon.assert.calledWith(window.ajax.get, `${CONSTANTS.STANDARDAPIURL}Geographic/ZipCode?cityName=city`)
    mockAjax.restore()
})

Also installed babel-plugin-istanbul package and
now the method covers as expected method coverage

Thanks

Leave a comment