2.0.2 • Published 1 year ago

fetch-reply-with v2.0.2

Weekly downloads
215
License
MIT
Repository
github
Last release
1 year ago

fetch-reply-with

npm version Tests

Simplifies unit tests by intercepting fetch requests and returning mocked responses.

Install

npm install --save-dev fetch-reply-with

Usage

require('fetch-reply-with'); // <- `fetch` is now globally available

// intercept GET http://orcascan.com and reply with...
fetch('http://orcascan.com', {

    // regular fetch option
    method: 'GET',

    // add reply for this fetch
    replyWith: {
        status: 200,
        body: 'Barcode Scanner app',
        headers: {
            'Content-Type': 'text/html'
        },
        delay: 500 // miliseconds to wait before responding (default = 0)
    }
});

// execute fetch request
fetch('http://orcascan.com').then(function(res){
    return res.text();
})
.then(function(text){
    // text === `Barcode Scanner app`
});

Couple of things to note:

  • Requests not setup with replyWith are executed as normal
  • A replyWith can be modified by redefining the replyWith

Unit Tests

The project includes unit tests, to run the tests:

  1. Checkout git clone https://github.com/john-doherty/fetch-reply-with
  2. Navigate into project folder cd fetch-reply-with
  3. Install dependencies npm install
  4. Run the tests npm test

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :)

Star the repo

If you find this useful please star the repo, it helps us prioritize fixes :raised_hands:

History

For change-log, check releases.

License

Licensed under MIT License © John Doherty

1.3.4

1 year ago

1.3.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.3.2

2 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.9

6 years ago

1.2.8

6 years ago

1.2.7

6 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago