From 22ec6fb509112cd83e78505a7c0c49a00e2329f0 Mon Sep 17 00:00:00 2001 From: falconmick Date: Wed, 23 May 2018 10:42:36 +0800 Subject: [PATCH] moxios with a axios instance added documentation on how to use moxios with a specific axios instance --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index b62a821..37e3868 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,30 @@ describe('mocking axios requests', function () { }) ``` +## Mocking a axios.create() instance + +``` +describe('some-thing', () => { + let axiosInstance; + beforeEach(() => { + axiosInstance = axios.create(); + moxios.install(axiosInstance); + }); + afterEach(() => { + moxios.uninstall(axiosInstance); + }); + it('should axios a thing', (done) => { + moxios.stubRequest('http://www.somesite.com/awesome-url', { + status: 200, + responseText: reducedAsxResponse + }); + axiosInstance.get('http://www.somesite.com/awesome-url') + .then(res => assert(res.status === 200)) + .finally(done); + }); +}); +``` + ## Thanks moxios is heavily inspired by [jasmine-ajax](https://github.com/jasmine/jasmine-ajax)