diff --git a/docs/.gitignore b/docs/.gitignore
new file mode 100755
index 0000000..0c3e5ab
--- /dev/null
+++ b/docs/.gitignore
@@ -0,0 +1,2 @@
+_site/
+.sass-cache/
diff --git a/docs/Gemfile b/docs/Gemfile
new file mode 100755
index 0000000..724febd
--- /dev/null
+++ b/docs/Gemfile
@@ -0,0 +1,8 @@
+source 'https://rubygems.org'
+
+gem 'jekyll', '3.7.2'
+
+group :jekyll_plugins do
+ gem 'jekyll-seo-tag', '2.4.0'
+ gem 'jekyll-sitemap', '1.2.0'
+end
diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock
new file mode 100755
index 0000000..0498c70
--- /dev/null
+++ b/docs/Gemfile.lock
@@ -0,0 +1,69 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ addressable (2.5.2)
+ public_suffix (>= 2.0.2, < 4.0)
+ colorator (1.1.0)
+ concurrent-ruby (1.0.5)
+ em-websocket (0.5.1)
+ eventmachine (>= 0.12.9)
+ http_parser.rb (~> 0.6.0)
+ eventmachine (1.2.5)
+ ffi (1.9.18)
+ forwardable-extended (2.6.0)
+ http_parser.rb (0.6.0)
+ i18n (0.9.3)
+ concurrent-ruby (~> 1.0)
+ jekyll (3.7.2)
+ addressable (~> 2.4)
+ colorator (~> 1.0)
+ em-websocket (~> 0.5)
+ i18n (~> 0.7)
+ jekyll-sass-converter (~> 1.0)
+ jekyll-watch (~> 2.0)
+ kramdown (~> 1.14)
+ liquid (~> 4.0)
+ mercenary (~> 0.3.3)
+ pathutil (~> 0.9)
+ rouge (>= 1.7, < 4)
+ safe_yaml (~> 1.0)
+ jekyll-sass-converter (1.5.2)
+ sass (~> 3.4)
+ jekyll-seo-tag (2.4.0)
+ jekyll (~> 3.3)
+ jekyll-sitemap (1.2.0)
+ jekyll (~> 3.3)
+ jekyll-watch (2.0.0)
+ listen (~> 3.0)
+ kramdown (1.16.2)
+ liquid (4.0.0)
+ listen (3.1.5)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+ ruby_dep (~> 1.2)
+ mercenary (0.3.6)
+ pathutil (0.16.1)
+ forwardable-extended (~> 2.6)
+ public_suffix (3.0.1)
+ rb-fsevent (0.10.2)
+ rb-inotify (0.9.10)
+ ffi (>= 0.5.0, < 2)
+ rouge (3.1.1)
+ ruby_dep (1.5.0)
+ safe_yaml (1.0.4)
+ sass (3.5.5)
+ sass-listen (~> 4.0.0)
+ sass-listen (4.0.0)
+ rb-fsevent (~> 0.9, >= 0.9.4)
+ rb-inotify (~> 0.9, >= 0.9.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jekyll (= 3.7.2)
+ jekyll-seo-tag (= 2.4.0)
+ jekyll-sitemap (= 1.2.0)
+
+BUNDLED WITH
+ 1.16.0
diff --git a/docs/LICENSE b/docs/LICENSE
new file mode 100755
index 0000000..fd1a855
--- /dev/null
+++ b/docs/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 James Newell - xhr-mock library
+Copyright (c) 2016 CloudCannon - Aviator Jekyll Theme
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/docs/README.md b/docs/README.md
new file mode 100755
index 0000000..8b13789
--- /dev/null
+++ b/docs/README.md
@@ -0,0 +1 @@
+
diff --git a/docs/_api/MockXMLHttpRequest.md b/docs/_api/MockXMLHttpRequest.md
new file mode 100755
index 0000000..9cb26e3
--- /dev/null
+++ b/docs/_api/MockXMLHttpRequest.md
@@ -0,0 +1,137 @@
+---
+title: MockXMLHttpRequest
+position: 1.2
+type:
+description:
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ MockXMLHttpRequest replaces XMLHttpRequest object.
+
+ For `xhr-mock.setup()` and `xhr-mock.teardown()` refer to XHRMock.
+
+ #### MockRequest
+
+ ##### .method() : *requestMethod*
+ * __description:__
+ * Gets the request method.
+ * __return:__
+ * method: returns method as a string in one of the following: `DELETE`, `GET`, `HEAD`, `OPTIONS`, `POST`, or `PUT`.
+
+
+ ##### .url() : *MockURL*
+
+ * __description:__
+ * Gets the request MockURL object.
+ * __return:__
+ * MockURL object.
+
+ ##### .header( *name* , *value* )
+ * __description:__
+ * Sets the request header's name and value.
+ * __parameters:__
+ * name : string
+ * value: string
+
+
+ ##### .header( *name* ) : *value*
+ * __description:__
+ * Gets a request header and returns the value as a string, or `null` if no header has been set.
+ * __parameters:__
+ * name: string
+ * __return:__
+ * value: string or `null`
+
+ ##### .headers() : *requestHeaders*
+ * __description:__
+ * Gets the request headers and returns the value as an object.
+ * __return:__
+ * headers: object
+
+ ##### .headers( *requestHeaders* )
+ * __description:__
+ * Sets the request headers.
+ * __parameters:__
+ * headers: object
+
+
+ ##### .body() : *requestBody*
+ * __description:__
+ * Gets the request body.
+ * __return:__
+ * body: string
+
+ ##### .body( *requestBody* )
+ * __description:__
+ * Sets the request body.
+ * __parameters:__
+ * body: string
+
+ #### MockResponse
+
+ ##### .status() : *value*
+ * __description:__
+ * Gets the response status.
+ * __return:__
+ * value: number
+
+ ##### .status( *code* )
+ * __description:__
+ * Sets the response status.
+ * __parameters:__
+ * code: number
+
+ ##### .reason() : *responseReason*
+ * __description:__
+ * Gets the response reason.
+ * __return:__
+ * reason: string
+
+ ##### .reason( *phrase* )
+ * __description:__
+ * Set the response reason.
+ * __parameters:__
+ * phrase: string
+
+ ##### .header( *name* , *value* )
+ * __description:__
+ * Sets a response header.
+ * __parameters:__
+ * name: string
+ * value: string
+
+ ##### .header( *name* ) : *value*
+ * __description:__
+ * Gets a response header and returns the value as a string or `null`
+ * __parameters:__
+ * name: string
+ * __return:__
+ * value: string or `null`
+
+ ##### .headers() : *responseHeaders*
+ * __description:__
+ * Get the response headers.
+ * __return:__
+ * headers: object
+
+ ##### .headers( *responseHeaders* )
+ * __description:__
+ * Set the response headers.
+ * __parameters:__
+ * headers: object
+
+ ##### .body() : *responseBody*
+ * __description:__
+ * Get the response body.
+ * __return:__
+ * body: string
+
+ ##### .body( *ResponseBody* )
+ * __description:__
+ * Set the response body.
+ * __parameters:__
+ * body: string
+
+
+---
diff --git a/docs/_api/Mock_Function.md b/docs/_api/Mock_Function.md
new file mode 100644
index 0000000..3243ba0
--- /dev/null
+++ b/docs/_api/Mock_Function.md
@@ -0,0 +1,17 @@
+---
+title: MockFunction
+position: 1.3
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ #### MockFunction
+ * __description:__
+ * function object used by XHRMock object for processing requests.
+ * __parameters__:
+ * req: MockRequest object.
+ * res: MockResponse object.
+ * __return:__
+ * MockResponse object or `undefined`.
+
+---
diff --git a/docs/_api/Mock_URL.md b/docs/_api/Mock_URL.md
new file mode 100644
index 0000000..cfade80
--- /dev/null
+++ b/docs/_api/Mock_URL.md
@@ -0,0 +1,37 @@
+---
+title: MockURL
+position: 1.4
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ #### MockUrl
+
+ ##### .protocol
+ * property .protocol is a **string** and not required.
+
+ ##### .username
+ * property .username is a **string** and not required.
+
+ ##### .password
+ * property .password is a **string** and not required.
+
+ ##### .host
+ * property .host is a **string** and not required.
+
+ ##### .path
+ * property .path is a **string** and not required.
+
+ ##### .port
+ * property .port is a **number** and is not required.
+
+ ##### .query
+ * {[name: string]: string};
+
+ ##### .hash
+ * property .hash is a **string** and is not required.
+
+ ##### .toString()
+ * method .toString formats and returns the url as a string
+
+---
diff --git a/docs/_api/_defaults.md b/docs/_api/_defaults.md
new file mode 100755
index 0000000..6a3419b
--- /dev/null
+++ b/docs/_api/_defaults.md
@@ -0,0 +1,12 @@
+---
+title:
+position:
+parameters:
+ - name:
+ content:
+content_markdown:
+left_code_blocks:
+ - code_block:
+ title:
+ language:
+---
diff --git a/docs/_api/xhr_mock.md b/docs/_api/xhr_mock.md
new file mode 100755
index 0000000..714eb20
--- /dev/null
+++ b/docs/_api/xhr_mock.md
@@ -0,0 +1,80 @@
+---
+title: XHRMock
+position: 1.1
+type:
+description:
+parameters:
+ - name:
+ content:
+ - name:
+ content:
+content_markdown: |-
+
+ Methods used to mock the `XMLHttpRequest` object:
+
+ ##### .setup()
+ * __description:__
+ * Replaces the global XMLHttpRequest object with the MockXMLHttpRequest.
+
+ ##### .teardown()
+ * __description:__
+ * Restores the global `XMLHttpRequest` object to its original state.
+
+ ##### .reset()
+ * __description:__
+ * Forgets all the request handlers.
+
+ ##### .get( *url* \| *regex* , *mock* )
+ * __description:__
+ * Registers mock as a factory function by passing it as a parameter
+ to the .get function. When XHRMock receives GET request, it then uses the registered mock function to process the request. If the request is as expected, the mock returns a response. For greater detail, look at the source code.
+ * __parameters__:
+ * the url is passed into the function as either a string or a `RegExp` object.
+ * mock is a factory function, `MockFunction`, passed into the .get function as a parameter.
+
+ ##### .post( *url* \| *regex* , *mock* )
+ * __description:__
+ * Registers mock as a factory function by passing it as a parameter
+ to the .post function. When XHRMock receives POST request, it then uses the registered mock function to process the request. If the request is as expected, the mock returns a response. For greater detail, look at the source code.
+ * __parameters__:
+ * the url is passed into the function as either a string or a `RegExp` object.
+ * mock is a factory function, `MockFunction`, passed into the .post function as a parameter.
+
+ ##### .patch( *url* \| *regex* , *mock* )
+ * __description:__
+ * Registers mock as a factory function by passing it as a parameter
+ to the .patch function. When XHRMock receives PATCH request, it then uses the registered mock function to process the request. If the request is as expected, the mock returns a response. For greater detail, look at the source code.
+ * __parameters__:
+ * the url is passed into the function as either a string or a `RegExp` object.
+ * mock is a factory function, `MockFunction`, passed into the .patch function as a parameter.
+
+ ##### .delete( *url* \| *regex* , *mock* )
+ * __description:__
+ * Registers mock as a factory function by passing it as a parameter
+ to the .delete function. When XHRMock receives DELETE request, it then uses the registered mock function to process the request. If the request is as expected, the mock returns a response. For greater detail, look at the source code.
+ * __parameters__:
+ * the url is passed into the function as either a string or a `RegExp` object.
+ * mock is a factory function, `MockFunction`, passed into the .delete function as a parameter.
+
+ ##### .use( *method* , *url* \| *regex* , *mock* )
+ * __description:__
+ * The .use function includes a method. .use registers mock as a factory function by passing it as a parameter
+ to the .use function. When XHRMock receives USE request, it then uses the registered mock function to process the request. If the request is as expected, the mock returns a response. For greater detail, look at the source code.
+ * __parameters__:
+ * the method is passed as a string.
+ * the url is passed into the function as either a string or a `RegExp` object.
+ * mock is a factory function, `MockFunction`, passed into the .use function as a parameter.
+
+ ##### .use( *mock* )
+ * __description:__
+ * Registers mock as a factory function to create mock responses for every request that passes through it. Url or method is not distinguished.
+ * __parameters__:
+ * mock is a factory function, `MockFunction`, passed into the .use function as a parameter.
+
+ ##### .error( *fn* )
+ * __description:__
+ * Logs errors thrown by handlers.
+ * __parameters__:
+ * function
+
+---
diff --git a/docs/_config.yml b/docs/_config.yml
new file mode 100755
index 0000000..bc01e12
--- /dev/null
+++ b/docs/_config.yml
@@ -0,0 +1,86 @@
+# ----
+# Site
+
+title: XHR-Mock
+description: XHR-Mock API documentation.
+url:
+google_analytics_key:
+permalink: pretty
+
+# -----
+# Build
+
+timezone: Etc/UTC
+
+collections:
+ documentation:
+ title: Documentation
+ position: 1
+ api:
+ title: APIs
+ position: 2
+ howto:
+ title: HowTo
+ position: 3
+plugins:
+ - jekyll-sitemap
+ - jekyll-seo-tag
+
+exclude:
+ - readme.md
+ - LICENSE
+
+defaults:
+ -
+ scope:
+ path: ""
+ values:
+ layout: default
+ -
+ scope:
+ type: "documentation"
+ values:
+ _hide_content: true
+ -
+ scope:
+ type: "api"
+ values:
+ _hide_content: true
+ -
+ scope:
+ type: "howto"
+ values:
+ _hide_content: true
+
+# -----------
+# CloudCannon
+
+types:
+ - get
+ - put
+ - delete
+ - post
+
+languages:
+ bash: Bash
+ c: C
+ css: CSS
+ html: HTML
+ java: Java
+ javascript: JavaScript
+ json: JSON
+ php: PHP
+ python: Python
+ ruby: Ruby
+
+_options:
+ content_markdown:
+ format: p h4 h5 h6
+ bold: true
+ italic: true
+ link: true
+ bulletedlist: true
+ numberedlist: true
+ image: true
+ table: true
+ styles: /css/editor.css
diff --git a/docs/_documentation/_defaults.md b/docs/_documentation/_defaults.md
new file mode 100755
index 0000000..6a3419b
--- /dev/null
+++ b/docs/_documentation/_defaults.md
@@ -0,0 +1,12 @@
+---
+title:
+position:
+parameters:
+ - name:
+ content:
+content_markdown:
+left_code_blocks:
+ - code_block:
+ title:
+ language:
+---
diff --git a/docs/_documentation/example.md b/docs/_documentation/example.md
new file mode 100755
index 0000000..1d3e21c
--- /dev/null
+++ b/docs/_documentation/example.md
@@ -0,0 +1,124 @@
+---
+title: Example
+position: 3
+parameters:
+ - name:
+ content:
+content_markdown: |-
+
+ `./createUser.js` demonstrates a use case of [XMLHttpRequest](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest).
+
+ Axios, jQuery, Superagent or another package can also be used instead of the native XMLHttpRequest object.
+ {: .info }
+
+
+
+ 2. A new XMLHttpRequest is created called `xhr`.
+ 3. the `.onreadystatechange` function is created for when the client receives the response from the server
+ 4. `xhr.open` initializes the request to the url.
+ 5. `xhr.setRequestHeader` sets the value of of the header, 'Content-Type' to JSON.
+ 6. `xhr.send` sends the request body to the server.
+
+
+ `./createUser.test.js`, shows unit tests using `xhr-mock` which replaces `XMLHttpRequest` with `MockXMLHttpRequest`.
+
+ 1. `mock.post` registers the url and `POST` method to the request handler.
+ 2. `createUser` method is called passing the parameter "John".
+ 3. `XHRMock` processes the request to the url, and:
+ * If the value of the request header is in JSON,
+ * If the request data is equal to "John",
+ 4. The response `"id": "abc-123"` is returned.
+
+
+left_code_blocks:
+ - code_block: |-
+ // createUser serves as the client.
+ export default function createUser(reqdata) {
+ return new Promise((resolve, reject) => {
+ // we create a new XMLHttpRequest object.
+ const xhr = new XMLHttpRequest();
+ // the onreadystatechange function is for receiving the response and checking the status.
+ xhr.onreadystatechange = () => {
+ if (xhr.readyState == XMLHttpRequest.DONE) {
+ if (xhr.status === 201) {
+ try {
+ resolve(JSON.parse(xhr.responseText).data);
+ } catch (error) {
+ reject(error);
+ }
+ } else if (xhr.status) {
+ try {
+ reject(JSON.parse(xhr.responseText).error);
+ } catch (error) {
+ reject(error);
+ }
+ } else {
+ eject(new Error('An error ocurred whilst sending the request.'));
+ }
+ }
+ };
+ // initializes the request to the url using the POST method, sets the request header value in JSON, and sends the request.
+ xhr.open('post', '/api/user');
+ xhr.setRequestHeader('Content-Type', 'application/json');
+ xhr.send(JSON.stringify({data: reqdata}));
+ });
+ }
+ title: ./createUser.js
+ language: javascript
+ - code_block: |-
+ // Tests the code with the mock request and response.
+ import mock from 'xhr-mock';
+ import createUser from './createUser';
+
+ describe('createUser()', () => {
+ // replaces the real XHR object with the mock XHR object before each test.
+ beforeEach(() => mock.setup());
+
+ // puts the real XHR object back and clears the mock after each test.
+ afterEach(() => mock.teardown());
+
+ it('should send the data as JSON', async () => {
+ expect.assertions(2);
+ // mock sets up the request function and registers the request from the client (createUser) to the request handler. If the request header is in JSON, and the request body is equal to "John," the response is returned: "id":"abc-123".
+ mock.post('/api/user', (req, res) => {
+ expect(req.header('Content-Type')).toEqual('application/json');
+ expect(req.body()).toEqual('{"data":{"name":"John"}}');
+ return res.status(201).body('{"data":{"id":"abc-123"}}');
+ });
+ // makes the requests as the client.
+ await createUser({name: 'John'});
+ });
+
+ it('should resolve with some data when status=201', async () => {
+ expect.assertions(1);
+
+ mock.post('/api/user', {
+ status: 201,
+ reason: 'Created',
+ body: '{"data":{"id":"abc-123"}}'
+ });
+
+ const user = await createUser({name: 'John'});
+
+ expect(user).toEqual({id: 'abc-123'});
+ });
+
+ it('should reject with an error when status=400', async () => {
+ expect.assertions(1);
+
+ mock.post('/api/user', {
+ status: 400,
+ reason: 'Bad request',
+ body: '{"error":"A user named \\"John\\" already exists."}'
+ });
+
+ try {
+ const user = await createUser({name: 'John'});
+ } catch (error) {
+ expect(error).toMatch('A user named "John" already exists.');
+ }
+ });
+ });
+ title: ./createUser.test.js
+ language: javascript
+---
diff --git a/docs/_documentation/getting_started.md b/docs/_documentation/getting_started.md
new file mode 100755
index 0000000..93bf2af
--- /dev/null
+++ b/docs/_documentation/getting_started.md
@@ -0,0 +1,27 @@
+---
+title: XHR-Mock
+position: 1
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ This is a utility for mocking XMLHttpRequest.
+ It's useful for testing, or prototyping while your backend is still being built.
+
+ It works in NodeJS and in the browser, and is compatible with:
+
+ * [Axios](https://www.npmjs.com/package/axios)
+ * [jQuery](https://www.npmjs.com/package/jquery)
+ * [Superagent](https://www.npmjs.com/package/superagent)
+
+ It may also work with other libraries built on XMLHttpRequest.
+
+ Standard compliant ([http://xhr.spec.whatwg.org/](http://xhr.spec.whatwg.org/)).
+
+ For more information, go to the [XHR-Mock GitHub Page](https://github.com/jameslnewell/xhr-mock/tree/master/packages/xhr-mock).
+
+left_code_blocks:
+ - code_block:
+ title:
+ language:
+---
diff --git a/docs/_documentation/installation.md b/docs/_documentation/installation.md
new file mode 100755
index 0000000..fc9f626
--- /dev/null
+++ b/docs/_documentation/installation.md
@@ -0,0 +1,38 @@
+---
+title: Installation
+position: 2
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ ##### With a Bundler
+
+ If you are using a bundler like [Webpack](https://www.npmjs.com/package/webpack) or [Browserify](https://www.npmjs.com/package/browserify) install `xhr-mock` using `yarn` or `npm`:
+
+ ```bash
+ yarn add --dev xhr-mock
+ ```
+
+ Now import `xhr-mock` and start using it in your scripts:
+
+ ```js
+ import mock from 'xhr-mock';
+ ```
+ ##### Without a Bundler
+
+ If you aren't using a bundler like [Webpack](https://www.npmjs.com/package/webpack) or [Browserify](https://www.npmjs.com/package/browserify) then add this script to your HTML:
+
+
+ ```html
+
+ ```
+
+
+ You can now start using the global, `XHRMock`, in your scripts!
+
+left_code_blocks:
+ - code_block:
+ title:
+ language:
+
+---
diff --git a/docs/_howto/delay_requests.md b/docs/_howto/delay_requests.md
new file mode 100644
index 0000000..02bb035
--- /dev/null
+++ b/docs/_howto/delay_requests.md
@@ -0,0 +1,20 @@
+---
+title: Delay requests
+position: 5.0
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ Requests can be delayed using our handy `delay` utility.
+left_code_blocks:
+ - code_block: |-
+ import mock, {delay} from 'xhr-mock';
+
+ mock.setup();
+
+ // delays the request for three seconds.
+ mock.post('/', delay({status: 201}, 3000));
+ title: Delay Request
+ language: javascript
+
+---
diff --git a/docs/_howto/oneoff_requests.md b/docs/_howto/oneoff_requests.md
new file mode 100644
index 0000000..071ca46
--- /dev/null
+++ b/docs/_howto/oneoff_requests.md
@@ -0,0 +1,20 @@
+---
+title: One-off requests
+position: 6.0
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ Requests can be made on one off occasions using our handy `once` utility.
+
+left_code_blocks:
+ - code_block: |-
+ import mock, {once} from 'xhr-mock';
+
+ mock.setup();
+
+ // the response will only be returned the first time a request is made.
+ mock.post('/', once({status: 201}));
+ title: One-off Request
+ language: javascript
+---
diff --git a/docs/_howto/proxy_requests.md b/docs/_howto/proxy_requests.md
new file mode 100644
index 0000000..8b90116
--- /dev/null
+++ b/docs/_howto/proxy_requests.md
@@ -0,0 +1,33 @@
+---
+title: Proxy requests
+position: 4.0
+parameters:
+ - name:
+ content:
+content_markdown: |-
+ If you want to mock some requests, but not all of them, you can proxy unhandled requests to a real server.
+left_code_blocks:
+ - code_block: |-
+ import mock, {proxy} from 'xhr-mock';
+
+ mock.setup();
+
+ // mock specific requests.
+ mock.post('/', {status: 204});
+
+ // proxy unhandled requests to the real servers.
+ mock.use(proxy);
+
+ // this request will receive a mocked response.
+ const xhr1 = new XMLHttpRequest();
+ xhr1.open('POST', '/');
+ xhr1.send();
+
+ // this request will receive the real response.
+ const xhr2 = new XMLHttpRequest();
+ xhr2.open('GET', 'https://jsonplaceholder.typicode.com/users/1');
+ xhr2.send();
+ title: Proxy Request
+ language: javascript
+
+---
diff --git a/docs/_howto/simulate_error.md b/docs/_howto/simulate_error.md
new file mode 100644
index 0000000..3d61ce9
--- /dev/null
+++ b/docs/_howto/simulate_error.md
@@ -0,0 +1,28 @@
+---
+title: Simulate error
+position: 3.0
+description:
+parameters:
+ - name:
+ content:
+ - name:
+ content:
+content_markdown: |-
+ Returns a `Promise` that rejects. If you want to test a particular error you use one of the pre-defined error classes.
+
+left_code_blocks:
+ - code_block: |-
+ import mock from 'xhr-mock';
+
+ mock.setup();
+
+ mock.get('/', () => Promise.reject(new Error()));
+
+ const xhr = new XMLHttpRequest();
+ xhr.onerror = event => console.log('error');
+ xhr.open('GET', '/');
+ xhr.send();
+ title: Simulate Error
+ language: javascript
+
+---
diff --git a/docs/_howto/simulate_progress.md b/docs/_howto/simulate_progress.md
new file mode 100644
index 0000000..d063c46
--- /dev/null
+++ b/docs/_howto/simulate_progress.md
@@ -0,0 +1,45 @@
+---
+title: Simulate progress
+position: 1.0
+#type: get
+description:
+parameters:
+ - name:
+ content:
+ - name:
+ content:
+content_markdown: |-
+ Sets the `Content-Length` header and sends a body. `xhr-mock` will emit `ProgressEvent`s.
+
+left_code_blocks:
+ - code_block: |-
+ import mock from 'xhr-mock';
+
+ mock.setup();
+
+ mock.post('/', {});
+
+ const xhr = new XMLHttpRequest();
+ xhr.upload.onprogress = event => console.log(event.loaded, event.total);
+ xhr.open('POST', '/');
+ xhr.setRequestHeader('Content-Length', '12');
+ xhr.send('Hello World!');
+ title: Upload progress
+ language: javascript
+ - code_block: |-
+ import mock from 'xhr-mock';
+
+ mock.setup();
+
+ mock.get('/', {
+ headers: {'Content-Length': '12'},
+ body: 'Hello World!'
+ });
+
+ const xhr = new XMLHttpRequest();
+ xhr.onprogress = event => console.log(event.loaded, event.total);
+ xhr.open('GET', '/');
+ xhr.send();
+ title: Download progress
+ language: javascript
+---
diff --git a/docs/_howto/simulate_timeout.md b/docs/_howto/simulate_timeout.md
new file mode 100644
index 0000000..429ce9b
--- /dev/null
+++ b/docs/_howto/simulate_timeout.md
@@ -0,0 +1,32 @@
+---
+title: Simulate timeout
+position: 2.0
+description:
+parameters:
+ - name:
+ content:
+ - name:
+ content:
+content_markdown: |-
+ Returns a `Promise` that never resolves or rejects.
+
+ A number of major libraries don't use the `timeout` event and use `setTimeout()` instead. Therefore, in order to mock timeouts in major libraries, we have to wait for the specified amount of time.
+ {: .info }
+
+left_code_blocks:
+ - code_block: |-
+ import mock from 'xhr-mock';
+
+ mock.setup();
+
+ mock.get('/', () => new Promise(() => {}));
+
+ const xhr = new XMLHttpRequest();
+ xhr.timeout = 100;
+ xhr.ontimeout = event => console.log('timeout');
+ xhr.open('GET', '/');
+ xhr.send();
+ title: Simulate Timeout
+ language: javascript
+
+---
diff --git a/docs/_includes/relative-src.html b/docs/_includes/relative-src.html
new file mode 100755
index 0000000..4535448
--- /dev/null
+++ b/docs/_includes/relative-src.html
@@ -0,0 +1 @@
+{% assign prefix = include.src | slice: 0, 2 %}{% assign protocol = include.src | slice: 0, 4 %}{% unless protocol == 'http' or prefix == "//" %}{{ site.baseurl }}{% endunless %}{{ include.src }}
\ No newline at end of file
diff --git a/docs/_includes/sidebar.html b/docs/_includes/sidebar.html
new file mode 100755
index 0000000..0d8ecfb
--- /dev/null
+++ b/docs/_includes/sidebar.html
@@ -0,0 +1,21 @@
+
+ {% assign sorted_collections = site.collections | sort: "position" %}
+ {% for collection in sorted_collections %}
+ {% if collection.label != "posts" %}
+
+
{{ collection.title }}
+
+ {% assign sorted_docs = collection.docs | sort: "position" %}
+ {% for doc in sorted_docs %}
+