Negotiating a POST request with moxios

Can moxios be used to fake a response to a POST request that matches not only the url but the body of the POST? Examining the body afterwards will work for me too.

This is what I am doing now. As far as I know, there are no method specific methods:

describe('createCode', function () {
    it('should create new code', function () {
        moxios.stubRequest(process.env.API_URL + '/games/GM01/codes', {
            status: 200
        })
    })
})

      

+3


source to share


1 answer


There is a way to check the latest axios request using moxios:

let request = moxios.requests.mostRecent()
expect(request.config.method).to.equal('post')
expect(JSON.parse(request.config.data)).to.deep.equal(code)

      



The config object is what is passed to axios data

- this is the request body.

+6


source







All Articles